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
I would expect that prop(foo, "bar") works the same way foo.bar does. However, if the type of the property is narrowed using type guards, the prop function stops working as expected:
interfaceFoo{bar?: number;}functionquux(foo: Foo){if(foo.bar){letbaz: number=prop(foo,"bar");// error TS2322: Type 'number | undefined' is not assignable to type 'number'.}}
Expected behavior: The code should compile just fine. Actual behavior: Compilation ends with a type error.
The text was updated successfully, but these errors were encountered:
Tentatively a duplicate of #10065 - type guards affect properties, but don't synthesize the kinds of on-the-fly new types that would be required to identify this in the general case. But here we should be ending up at the same symbol and resolving this correctly
TypeScript Version: 2.1.4
Consider this simple property getter function (defined in What's New of TypeScript 2.1):
I would expect that
prop(foo, "bar")
works the same wayfoo.bar
does. However, if the type of the property is narrowed using type guards, theprop
function stops working as expected:Expected behavior: The code should compile just fine.
Actual behavior: Compilation ends with a type error.
The text was updated successfully, but these errors were encountered: