Skip to content

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

Closed
@janicduplessis

Description

@janicduplessis

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions