Skip to content

Wrong property-will-be-overwritten-by-spread error when property is any #37740

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
janicduplessis opened this issue Apr 1, 2020 · 1 comment · Fixed by #37757
Closed

Wrong property-will-be-overwritten-by-spread error when property is any #37740

janicduplessis opened this issue Apr 1, 2020 · 1 comment · Fixed by #37757
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@janicduplessis
Copy link

janicduplessis commented Apr 1, 2020

TypeScript Version: 3.9.0-dev.20200328

Search Terms:

property-will-be-overwritten-by-spread

Code

type A = {
    a?: any
}

const a: A = {};
const b = {  a: 'zzz', ...a, }; // 'a' is specified more than once, so this usage will be overwritten

Using string instead of any as the type of a property in A works as expected.

Expected behavior:

No error

Actual behavior:

'a' is specified more than once, so this usage will be overwritten.(2783)
input.ts(6, 24): This spread always overwrites this property.

Playground Link:

Using any errors - bug

https://www.typescriptlang.org/play/?ts=3.9.0-dev.20200328&ssl=6&ssc=32&pln=1&pc=1#code/C4TwDgpgBAglC8UDeAoK6oEMD8AuLAdiCgL4ooDGA9gQM7Bb5yJIkDclN9UARgsukz4A5AC9xwgDRQAdHMzT2QA

Using string no error - works as expected

https://www.typescriptlang.org/play/?ts=3.9.0-dev.20200328#code/C4TwDgpgBAglC8UDeAoK6oEMD8AuKAzsAE4CWAdgOYoC+KKAxgPblFb5yJI0DcjLbAEYJk6TPgDkALxkSANFAB0yzAt5A

Related Issues: #36779

@sandersn
Copy link
Member

sandersn commented Apr 1, 2020

Might be the fact that a is an optional property but doesn't have undefined in the type (because any eats it).

@sandersn sandersn added this to the TypeScript 3.9.0 milestone Apr 1, 2020
@sandersn sandersn added the Bug A bug in TypeScript label Apr 1, 2020
@sandersn sandersn self-assigned this Apr 1, 2020
sandersn added a commit that referenced this issue Apr 2, 2020
Previously, spreading an optional any gave a bogus error when the name
conflicted with earlier properties in the object literal. Now the code
checks any types for optionality before issuing the error.

Fixes #37740
@sandersn sandersn added the Fix Available A PR has been opened for this issue label Apr 2, 2020
sandersn added a commit that referenced this issue Apr 2, 2020
Previously, spreading an optional any gave a bogus error when the name
conflicted with earlier properties in the object literal. Now the code
checks any types for optionality before issuing the error.

Fixes #37740
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants