Closed
Description
TypeScript Version: 4.0.0-dev
Search Terms: Object assign, spread
Code
// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
const production: boolean = true;
interface Icon {
x: number;
y: number;
name: 'we' | 'you' | 'hello' | undefined;
}
const myBeautifulIcon: Icon = Object.assign(
{ x: 2, y: 2 },
production ? { name: 'we' } : { name: 'you' }
)
console.log(myBeautifulIcon);
(code tested in nightly ts playground)
Expected behavior:
The code to be valid and myBeautifulIcon
object have correct type. The correct type should be concluded from Object assign.
Actual behavior:
Error arised, saying that theconcluded type for name
was string;