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
When strictNullChecks is disabled (as in JS code), destructuring a variable of type unknown produces the message:
Property 'foo' does not exist on type '{}'.(2339)
Whereas with it enabled, the error is:
Property 'foo' does not exist on type 'unknown'.(2339)
This behavior isn't actually tested anywhere, and was revealed in #47442.
When assigning unknown to a variable of some class type with properties, a similar error is produced:
Property 'prop' is missing in type '{}' but required in type 'A'.(2741)
Whereas strictNullChecks = true produces a more obvious error:
Type 'unknown' is not assignable to type 'A'.(2322)
This behavior (and other errors like it) is actually captured in a few tests.
This all seems to stem from the fact that getApparentType returns the empty object type as unknown's apparent type, which was added in #30637.
I would personally argue that the latter errors in the above examples make more sense than referring to {}, which doesn't actually appear in the code anywhere. Right now, this doesn't seem to be very visible (as people in JS are unlikely to see unknown), but with #47383 / #47442, this may become more visible.
Now that I think a bit harder, this message won't show up in JS without checkJs, so maybe this isn't a huge deal after all, but it is a little awkward if anyones's running with strictNullChecks off.
When
strictNullChecks
is disabled (as in JS code), destructuring a variable of typeunknown
produces the message:Whereas with it enabled, the error is:
This behavior isn't actually tested anywhere, and was revealed in #47442.
When assigning
unknown
to a variable of some class type with properties, a similar error is produced:Whereas
strictNullChecks = true
produces a more obvious error:This behavior (and other errors like it) is actually captured in a few tests.
This all seems to stem from the fact that
getApparentType
returns the empty object type asunknown
's apparent type, which was added in #30637.I would personally argue that the latter errors in the above examples make more sense than referring to
{}
, which doesn't actually appear in the code anywhere. Right now, this doesn't seem to be very visible (as people in JS are unlikely to seeunknown
), but with #47383 / #47442, this may become more visible.Playground Link
Split off from #47442 (comment).
The text was updated successfully, but these errors were encountered: