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
This can only narrow arg1. TS only narrows variables directly involved in the conditional expression and doesn't track relationships with other variables.
TypeScript Version: 3.4.4 and [email protected]
Search Terms:
Code
Expected behavior:
Since arg1 and arg2 have same names property first should also exist on arg2
Actual behavior:
Property 'first' does not exist on type 'someType'.
Property 'first' does not exist on type '{ name: "second"; second: string; }'.ts(2339)
Playground Link:
https://www.typescriptlang.org/play/#src=type%20someType%20%3D%20%7B%0D%0A%20%20name%3A%20'first'%2C%0D%0A%20%20first%3A%20string%2C%0D%0A%7D%20%7C%20%7B%0D%0A%20%20name%3A%20'second'%2C%0D%0A%20%20second%3A%20string%2C%0D%0A%7D%0D%0A%0D%0Afunction%20someFunction(arg1%3A%20someType%2C%20arg2%3A%20someType)%20%7B%0D%0A%20%20if%20(arg1.name%20%3D%3D%3D%20arg2.name)%20%7B%0D%0A%20%20%20%20if%20(arg1.name%20%3D%3D%3D%20'first')%20%7B%0D%0A%20%20%20%20%20%20%2F%2F%20Here%20compiler%20shows%20an%20error%0D%0A%20%20%20%20%20%20console.log(arg2.first)%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%7D
The text was updated successfully, but these errors were encountered: