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 compiler reduces empty intersection types to never when used in a union. an empty intersection type is one whose constituents are all unit types. so 1 & 2 "a" & false or "s" & unique symbol.
so PhantomString | null is just null. see #18438 for more details.
Ah ok, I see. Using type PhantomString = string & { "phantom-string": any }; seems to work. I can see there are a few issues suggesting true nominal typing support so I'll add my 👍 to those.
TypeScript Version: 3.0.0-dev.20180609 & 2.9.1
Search Terms:
Narrowing unique symbol union
Code
Expected behavior:
fn
andfn2
should be reported as:Actual behavior:
fn
andfn2
are reported as:Playground Link:
https://www.typescriptlang.org/play/#src=declare%20const%20phantom%3A%20unique%20symbol%3B%0D%0Atype%20Phantom%20%3D%20typeof%20phantom%3B%0D%0Atype%20PhantomString%20%3D%20string%20%26%20Phantom%3B%0D%0A%0D%0Aconst%20fn%20%3D%20(arg%3F%3A%20PhantomString)%20%3D%3E%20arg%3B%0D%0A%0D%0Aconst%20fn2%20%3D%20(arg%3A%20Array%3CPhantomString%20%7C%20null%3E)%20%3D%3E%20arg%3B
Appears to be partially related to
strictNullChecks
The text was updated successfully, but these errors were encountered: