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
type inside function, scope variable, type narrowing
https://www.typescriptlang.org/play/?target=99&ts=5.7.0-dev.20240924#code/DYUwLgBAtghgngIxAZTAJwJYDsDmAuCAZ3WxwB8sBXYYCAXgipoG4AoWRFE3eiAIgAefNu3hJUmXGwD00iAD0A-K1YBjAPZZiEAGYBGXgAoAlPQB8EAN6sIt6GK6ScbOxFkLlAXxU7KWVWAYmroATCZWNnYc4tzOkbbuSqyeQA
let maybeString: string | null = null; maybeString = "x"; maybeString; // ^? let maybeString: string const f1 = () => { maybeString; // ^? let maybeString: string | null } function f2() { maybeString; // ^? let maybeString: string | null }
The type of maybeString in both functions is string | null .
maybeString
string | null
The type of maybeString in both functions should be string as it was narrowed before these functions were defined.
string
No response
The text was updated successfully, but these errors were encountered:
Duplicate of #9998.
Sorry, something went wrong.
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
π Search Terms
type inside function, scope variable, type narrowing
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?target=99&ts=5.7.0-dev.20240924#code/DYUwLgBAtghgngIxAZTAJwJYDsDmAuCAZ3WxwB8sBXYYCAXgipoG4AoWRFE3eiAIgAefNu3hJUmXGwD00iAD0A-K1YBjAPZZiEAGYBGXgAoAlPQB8EAN6sIt6GK6ScbOxFkLlAXxU7KWVWAYmroATCZWNnYc4tzOkbbuSqyeQA
π» Code
π Actual behavior
The type of
maybeString
in both functions isstring | null
.π Expected behavior
The type of
maybeString
in both functions should bestring
as it was narrowed before these functions were defined.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: