Closed
Description
TypeScript Version: nightly (2.2.0-dev.20161203)
Code:
const enum E { Hey, Ho }
type A = {
x: E.Hey;
y: string;
}
type B = {
x: E.Ho;
y: number;
}
var zzz: A | B = { x: 1, y: "hello" }; // Doesn't error
var zzz: A | B = { x: 54, y: "hello" }; // Doesn't error
Expected behavior:
Should error.
Actual behavior:
Doesn't error.
For comparison:
type A = {
x: 0;
y: string;
}
type B = {
x: 1;
y: number;
}
var zzz: A | B = { x: 1, y: "hello" }; // Errors as expected
/*
'Type '{ x: 1; y: string; }' is not assignable to type 'A | B'.
Type '{ x: 1; y: string; }' is not assignable to type 'B'.
Types of property 'y' are incompatible.
Type 'string' is not assignable to type 'number'.'
*/
var zzz: A | B = { x: 54, y: "hello" }; // Errors as expected
/*
'Type '{ x: 54; y: string; }' is not assignable to type 'A | B'.
Type '{ x: 54; y: string; }' is not assignable to type 'B'.
Types of property 'x' are incompatible.
Type '54' is not assignable to type '1'.'
*/