unknow
8000
n
should narrow to {}
when non-null
#48928
Labels
Duplicate
An existing issue was already created
Bug Report
🔎 Search Terms
empty type, unknown, top type, unknown not null
🕗 Version & Regression Information
Starting 3.0 (when
unknown
was introduced) and until at least 4.6.2⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
🙂 Expected behavior
I believe narrowing should be happening.
unkown
is the top type for everything.{}
is the top type for everything non-null
non-undefined
. Therefore, when anunknown
is or'ed (||
or??
) with a non-null, or if checked not-null itself (if (myUnknown != null)
), then the result should be narrowed to{}
.Extra context: I'm trying to wrap around
JSON.parse
to return{}
when the result is null. I would have expected that:Be of the type
{}
, but TypeScript is insisting that it's actuallyunknown
.The text was updated successfully, but these errors were encountered: