You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compilation fails because TS thinks that a may be null when returning it from getA.
π Expected behavior
Because throwError is never, TS should be able to see that I will never reach the return statement if a is null (or falsy at all). Even if I explicitly check for if (a == null), control flow analysis does not seem to narrow the type here.
So, expected behavior is that compilation succeeds and the type is narrowed to just string.
I see this related issue which implies that I should be able to narrow my type by calling a never function: #50739 , but I cannot reproduce the behavior of narrowing a.
The text was updated successfully, but these errors were encountered:
As part of an interface, the method is already explicitly typed.
However, if youβre calling it as a method, then the object itβs called through (ctx in this case) also must have an explicit type annotation. The relevant text from #32695 is:
A function call is analyzed as an assertion call or never-returning call when β¦ each identifier in the function name references an entity with an explicit type β¦ and
the function name resolves to a function type with an asserts return type or an explicit never return type annotation.
Bug Report
π Search Terms
some variations/permutations of "narrow never null"
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Compilation fails because TS thinks that
a
may be null when returning it fromgetA
.π Expected behavior
Because
throwError
isnever
, TS should be able to see that I will never reach the return statement ifa
is null (or falsy at all). Even if I explicitly check forif (a == null)
, control flow analysis does not seem to narrow the type here.So, expected behavior is that compilation succeeds and the type is narrowed to just
string
.I see this related issue which implies that I should be able to narrow my type by calling a
never
function: #50739 , but I cannot reproduce the behavior of narrowinga
.The text was updated successfully, but these errors were encountered: