Skip to content

Error property-will-be-overwritten-by-spread for non-enumerable properties #38589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
benurb opened this issue May 15, 2020 · 1 comment
Closed
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@benurb
Copy link

benurb commented May 15, 2020

TypeScript Version: 3.9.2, 4.0.0-dev.20200514, latest master (7fc456f)

Search Terms:

  • This spread always overwrites this property
  • Error spread
  • strictNullChecks

Code

const err = new Error("Error reason");
console.log({
    message: err.message,
    ...err
});

Expected behavior:
Compiles sucessfully using strictNullChecks compiler option. Works correctly with typescript 3.8.3.

Actual behavior:
Compilation fails even though the spread does not overwrite anything since message is a non-enumarable property on Error. Without setting strictNullChecks it works correctly in typescript 3.9.2.

test.ts:3:5 - error TS2783: 'message' is specified more than once, so this usage will be overwritten.

3     message: err.message,
      ~~~~~~~~~~~~~~~~~~~~

  test.ts:4:5
    4     ...err
          ~~~~~~
    This spread always overwrites this property.

Playground Link:

Related Issues: #38577 seems to be a fix for a similar problem

@RyanCavanaugh RyanCavanaugh added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Jun 8, 2020
@RyanCavanaugh
Copy link
Member

TS doesn't track enumerability, so has no way to know that this isn't a misordered spread. See #9726

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

2 participants