Closed
Description
TypeScript Version: 3.9.2, also in 4.0.0-beta (not in 3.8.3)
Search Terms:
2783
Expected behavior:
code should be accepted without error
Actual behavior:
error 2783 ist raised
Related Issues:
#38535, #39113, #36779, #37740
Code
(the actual code builds obj
in a loop, but this small example shows the issue; btw, if you delete the x: 0,
, there is no error, which is also not correct)
let obj: {[key: string]: {x: number}} = {};
// erroneous type error:
// 'x' is specified more than once, so this usage will be overwritten.(2783)
// input.tsx(3, 21): This spread always overwrites this property
obj['key'] = {x: 0, ...obj['key']}; // x would be in obj['key'], if 'key' was in obj
Output
"use strict";
let obj = {};
// erroneous type error:
// 'x' is specified more than once, so this usage will be overwritten.(2783)
// input.tsx(3, 21): This spread always overwrites this property
obj['key'] = Object.assign({ x: 0 }, obj['key']); // x would be in obj['key'], if 'key' was in obj
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided
potentially relevant: https://stackoverflow.com/questions/47155141/spreading-undefined-in-array-vs-object