-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TypeScript Version: 2.7.0-dev.20171202
Code
interface Square {
kind: "square";
size: number;
}
interface Circle {
kind: "circle";
radius: number;
}
type Shape = Square | Circle;
function withDefault(s1: Shape, s2: Shape): string {
switch (s1.kind) {
case "square":
return "1";
case "circle":
switch (s2.kind) {
case "square":
return "2";
case "circle":
return "3";
default:
return "never";
}
}
}
function withoutDefault(s1: Shape, s2: Shape): string {
switch (s1.kind) {
case "square":
return "1";
case "circle":
switch (s2.kind) {
case "square":
return "2";
case "circle":
return "3";
}
}
}
run with tsc --strict
Expected behavior:
Shape has two kinds only, there is no error with withoutDefault
.
Actual behavior:
error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed