Skip to content

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

Closed
@benurb

Description

@benurb

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions