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
I expect that, since throwError has return type never, that TypeScript would be able to deduce through control flow analysis that a has been initialized when console.log(a) is called.
(This works as expected if the throwError(); line is replaced with the more direct throw new Error().)
Actual behavior:
I get an error
a.ts(13,13): error TS2454: Variable 'a' is used before being assigned.
The text was updated successfully, but these errors were encountered:
There is a difference between a function typed as () => never and to saying that a call to that function implies always throws. But practically, I guess they mean the same thing.
If the compiler were to do this, wouldn't it also make sense that calling such functions unconditionally should change the callers inferred return type to never? That does not happen today, I don't know if it is by design.
In the above f has type () => never, but only because I annotated it as such, while g has type () => void. If you were reviewing this code, you would probably think that calling g indicates a programmer error unless it actually through some conventional NotImplemenetedError.
TypeScript Version: 2.0.3
Code
With
--strictNullChecks
,Expected behavior:
I expect that, since
throwError
has return typenever
, that TypeScript would be able to deduce through control flow analysis thata
has been initialized whenconsole.log(a)
is called.(This works as expected if the
throwError();
line is replaced with the more directthrow new Error()
.)Actual behavior:
I get an error
a.ts(13,13): error TS2454: Variable 'a' is used before being assigned.
The text was updated successfully, but these errors were encountered: