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
The intersection of non-null/undefined types with null and undefined is not deduced to be never. Instead, things like string & null persist unchanged. (This is with strict null checking.) This also applies to singleton types, so the type "a" & "b" is not deduced to be never.
TypeScript Version: 3.5.1
Search Terms: primitive null intersection never
Code
typeT=string&null;typeU=Textendsnever ? number : never;consta: U=1;
Expected behavior: T is deduced to be never, so U is number, so it compiles.
Actual behavior: The code does not compile because T is not deduced to be never and so U is never.
Ah, thank you. Reading through that PR, it seems that pre-3.6, the reduction can be forced by taking a union, so e.g. (string & null) | never reduces to never.
The intersection of non-null/undefined types with
null
andundefined
is not deduced to benever
. Instead, things likestring & null
persist unchanged. (This is with strict null checking.) This also applies to singleton types, so the type"a" & "b"
is not deduced to benever
.TypeScript Version: 3.5.1
Search Terms: primitive null intersection never
Code
Expected behavior: T is deduced to be
never
, so U isnumber
, so it compiles.Actual behavior: The code does not compile because T is not deduced to be
never
and soU
isnever
.Playground Link: https://www.typescriptlang.org/play/#code/C4TwDgpgBAKlC8UDOwBOBLAdgcygMikwFcAbEgbgChRIoBVBWKCAD2AkwBMlCIA3CKigB+QkQC2AI0FQAXLwGoqAYwD2mFFACG8hogCM5IA
The text was updated successfully, but these errors were encountered: