unknown
non-null object type restriction bug
#29618
Labels
Duplicate
An existing issue was already created
TypeScript Version: 3.2.2
Search Terms:
unknown non-null object type restriction bug
Code
Expected behavior:
those 2 lines should work the same
Actual behavior:
they don't
Playground Link: https://www.typescriptlang.org/play/#src=type%20Indexable%20%3D%20%7B%20%5Bkey%3A%20string%5D%3A%20unknown%20%7D%0D%0Aconst%20data%3A%20Indexable%20%3D%20%7B%7D%0D%0A%0D%0Afunction%20navigate(index%3A%20Indexable%2C%20seg%3A%20string%20%7C%20number)%3A%20Indexable%20%7B%0D%0A%20%20%20%20if%20(seg%20in%20index)%20%7B%0D%0A%20%20%20%20%20%20%20%20const%20next%20%3D%20index%5Bseg%5D%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20DONT%20WORKS%0D%0A%20%20%20%20%20%20%20%20if%20(next%20!%3D%20null%20%26%26%20typeof%20next%20%3D%3D%3D%20'object')%20return%20next%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20Type%20'object%20%7C%20null'%20is%20not%20assignable%20to%20type%20'Indexable'.%0D%0A%20%20%20%20%20%20%20%20%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20WORKS%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20if%20(typeof%20next%20%3D%3D%3D%20'object'%20%26%26%20next%20!%3D%20null)%20return%20next%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20throw%20new%20Error('--')%0D%0A%7D%20%0D%0A
Related Issues:
The text was updated successfully, but these errors were encountered: