You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type checking is ignored with spread operator, especially with truthy expression.Β #57248
Tested with www.typescriptlang.org with versions from 3.3.3 to nightly (v5.4.0-dev.20240131)
β― Playground Link
No response
π» Code
typeType={property: string,}lettypedVar1: Type={property: 'string',anotherProperty: 'foo',// TS-2353: Object literal may only specify known properties, and 'anotherProperty' does not exist in type 'Type'.}lettypedVar2: Type={property: 'string',
...({anotherProperty: 'bar'}),// No error}lettypedVar3: Type={property: 'string',anotherProperty: 'foo',// TS-2783: 'anotherProperty' is specified more than once, so this usage will be overwritten.
...({anotherProperty: 'bar'}),}lettypedVar4: Type={property: 'string',anotherProperty: 'foo',// No error, total ingoring
...(1==1&&{anotherProperty: 'bar'}),}console.log(typedVar2);// {"property": "string", "anotherProperty": "bar"} console.log(typedVar2.anotherProperty);// TS-2339 : Property 'anotherProperty' does not exist on type 'Type'.console.log(typedVar4);// {"property": "string", "anotherProperty": "bar"} console.log(typedVar4.anotherProperty);// TS-2339 : Property 'anotherProperty' does not exist on type 'Type'.
π Actual behavior
TS-2353: Object literal may only specify known properties, and 'anotherProperty' does not exist in type 'Type'
No error
TS-2783: 'anotherProperty' is specified more than once, so this usage will be overwritten.
No error
π Expected behavior
TS-2353: Object literal may only specify known properties, and 'anotherProperty' does not exist in type 'Type'
TS-2353: Object literal may only specify known properties, and 'anotherProperty' does not exist in type 'Type'
le sigh... this error message really needs to be softened to make it more obvious EPC isn't a type check.
Count this as another vote for something like #55152 (comment)
Activity
MartinJohns commentedon Jan 31, 2024
Duplicate of #39998. Type checking is not ignored and works, just excess property checks not.
fatcerberus commentedon Jan 31, 2024
le sigh... this error message really needs to be softened to make it more obvious EPC isn't a type check.
Count this as another vote for something like #55152 (comment)
typescript-bot commentedon Feb 4, 2024
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.