We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Control Flow Analysis for Dependent Parameters generic
v4.7.0-dev.20220302
Playground link with relevant 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 } };
parameter type not narrowed
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");
The text was updated successfully, but these errors were encountered:
@ahejlsberg thoughts?
Sorry, something went wrong.
Yeah, that ought to work. Very easy fix. I'll put up a PR.
ahejlsberg
Successfully merging a pull request may close this issue.
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
π Actual behavior
parameter type not narrowed
π Expected behavior
parameter type is narrowed, like in the example from the typescript 4.6 blog post
The text was updated successfully, but these errors were encountered: