Closed as not planned
Closed as not planned
Description
π Search Terms
spread operator with expression
π Version & Regression Information
- Tested with www.typescriptlang.org with versions from 3.3.3 to nightly (v5.4.0-dev.20240131)
β― Playground Link
No response
π» Code
type Type = {
property: string,
}
let typedVar1: Type = {
property: 'string',
anotherProperty: 'foo', // TS-2353: Object literal may only specify known properties, and 'anotherProperty' does not exist in type 'Type'.
}
let typedVar2: Type = {
property: 'string',
...({anotherProperty: 'bar'}), // No error
}
let typedVar3: Type = {
property: 'string',
anotherProperty: 'foo', // TS-2783: 'anotherProperty' is specified more than once, so this usage will be overwritten.
...({anotherProperty: 'bar'}),
}
let typedVar4: 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'
- TS-2353 + TS-2783
- TS-2353 + TS-2783
Additional information about the issue
No response