-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Control Flow Analysis for Dependent Parameters doesn't work when the parameters are genericย #48345
Copy link
Copy link
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
Bug Report
๐ Search Terms
Control Flow Analysis for Dependent Parameters generic
๐ Version & Regression Information
v4.7.0-dev.20220302
โฏ Playground Link
Playground link with relevant code
๐ป Code
type Func = <T extends ["a", number] | ["b", string]>(...args: T) => void;
const f1: Func = (kind, payload) => {
if (kind === "a") {
payload.toFixed(); // error
}
if (kind === "b") {
payload.toUpperCase(); // error
}
};๐ Actual behavior
parameter type not narrowed
๐ Expected behavior
parameter type is narrowed, like in the example from the typescript 4.6 blog post
type Func = (...args: ["a", number] | ["b", string]) => void;
const f1: Func = (kind, payload) => {
if (kind === "a") {
payload.toFixed(); // 'payload' narrowed to 'number'
}
if (kind === "b") {
payload.toUpperCase(); // 'payload' narrowed to 'string'
}
};
f1("a", 42);
f1("b", "hello");Reactions are currently unavailable
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