-
Notifications
You must be signed in to change notification settings - Fork 13.3k
No implicit returns error in exhaustive if statement #17358
Copy link
Copy link
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TS 2.4.1 with noImplicitReturns enabled
class A {}
class B {}
// error: Not all code paths return a value.
const fn = (x: A | B) => {
if (x instanceof A) {
x // A
return 1
} else if (x instanceof B) {
x // B
return 2
} else {
x // never
}
}I would not expect this to error because the if statement is exhaustive, therefore all code paths do return a value.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed