Closed
Description
I'm not sure if it's a bug.
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
playground, 2.5.1-insiders.20170825
Code
interface Square {
kind: "square";
size: number;
}
interface Rectangle {
kind: "rectangle";
width: number;
height: number;
}
type Shape = Square | Rectangle;
var a: Square = { kind: 'square', size: 100, width: 50 }; // error
var b: Shape = { kind: 'square', size: 100, width: 50 }; // oops
Expected behavior:
Same error. From the kind
property, TypeScript should understand that the second object literal is of type Square
and prevent us from attaching the width
property to it.
Actual behavior:
no error