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
{{ message }}
Repository navigation
Unable to narrow parameterized generic types for functions #25039
With strictNullChecks enabled your code won't even compile, because the type null is not compatible with the type 'a' | 'b'.
Without strictNullChecks the value null is implicitly compatible with every type. When you call test(null) the compiler resolves to any because it can't figure out the type of T. Based on null the compiler can't deduct any sensible type. You could expect that it should return 'a' | 'b', because T must extend from it, but that would still only be a "guess". There's no T-type known.
I think I communicated the issue confusingly, it was not about the actual return type but the type guard in the implementation, I edited the first post to reflect that.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
[-]Unable to narrow generic types for functions[/-][+]Unable to narrow parameterized generic types for functions[/+]MartinJohns commentedon Jun 18, 2018
With
strictNullChecksenabled your code won't even compile, because the typenullis not compatible with the type'a' | 'b'.Without
strictNullChecksthe valuenullis implicitly compatible with every type. When you calltest(null)the compiler resolves toanybecause it can't figure out the type ofT. Based onnullthe compiler can't deduct any sensible type. You could expect that it should return'a' | 'b', becauseTmust extend from it, but that would still only be a "guess". There's noT-type known.lingz commentedon Jun 18, 2018
I think I communicated the issue confusingly, it was not about the actual return type but the type guard in the implementation, I edited the first post to reflect that.
mhegazy commentedon Jun 19, 2018
Duplicate of #13995
typescript-bot commentedon Jul 5, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.