-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
π Version & Regression Information
- This is the behavior in every version I tried.
β― Playground Link
π» Code
function f1<T>(x: T & string | T & undefined) {
if (x) {
x; // Should narrow to T & string
}
}
function f2<T>(x: T & string | T & undefined) {
if (x !== undefined) {
x; // Should narrow to T & string
}
else {
x; // Should narrow to T & undefined
}
}
function f3<T>(x: T & string | T & number) {
if (typeof x === "string") {
x; // Should narrow to T & string
}
else {
x; // Should narrow to T & number
}
}
function f4<T>(x: T & 1 | T & 2) {
switch (x) {
case 1: x; break; // T & 1
case 2: x; break; // T & 2
default: x; // Should narrow to never
}
}
function f5<T extends string | number>(x: T & number) {
const t1 = x === "hello"; // Should be an error
}
π Actual behavior
No narrowing or errors where expected.
π Expected behavior
Narrowing and errors as indicated above.
jonhue
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue