-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
interface Square {
kind: "square";
size: number;
}
interface Rectangle {
kind: "rectangle";
width: number;
height: number;
}
interface Circle {
kind: "circle";
radius: number;
}
type Shape = Square | Rectangle | Circle;
let shape: Shape = {
kind: "square",
width: 10,
height: 10
}So we create object with type Shape of kind square and try to pass incorrect other props (for this kind), and TS emits the error that object is no assignable to last type that is in union (Circle in this case). I believe it would be better if TS would recoginze that we are trying to make Square type in this case and emitted corresponding error message.
rictic
Metadata
Metadata
Assignees
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
