Narrowed const
variables are widened in block-scoped closures
#61158
Labels
Help Wanted
You can do this
Possible Improvement
The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
π Search Terms
narrowing, cfa, closure,
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?noUncheckedIndexedAccess=true&target=99&ts=5.8.0-dev.20250209#code/CYUwxgNghgTiAEYD2A7AzgF3mgXNjMAligOYDcAUBYQGbwAUa8AvK-AOQ1JLsCU8AbwrwRiVJmwBBCIShNm2SqPg0ArijAZCqeACMowevyHLlydFi5I8nbuxaLhogL5VlajVp0luh409MxCxVuGyt7BTRpWTQlFwpXChAADwAHJBgsAWcgA
π» Code
π Actual behavior
error trying to use the variable as its narrowed value.
π Expected behavior
No error.
bad()
is a local function only reachable within the scope in whichs
has been definitely narrowed to'foo'
.Additional Information
Found organically in typescript-eslint/typescript-eslint#10182 (comment) (with a narrowed member access corollary)
The text was updated successfully, but these errors were encountered: