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
Search Terms: user type guard function nested guarding
Code
typeTest=TestOne|TestTwo;interfaceTestOne{type: 'one'}interfaceTestTwo{type: 'two'}constisTest=(data: unknown): data is Test=>truedeclarevarpayload: anyif(isTest(payload)){if(payload.type==='two'){// expected to be `TestTwo`, doesn't workpayload}}constcastedPayload=payloadasTestif(castedPayload.type==='two'){// expected to be `TestTwo`, suddenly workscastedPayload}
Expected behavior:
Test should be type guarded and become TestTwo inside the if statement.
Actual behavior:
Test is not type guarded after the check. It remains Test.
Strangely enough, if payload is manually cast with as to be Test, type guarding suddenly works.
So, it seems to be tighed some how to the user type guard function isTest.
TypeScript Version: 3.6.3
Search Terms: user type guard function nested guarding
Code
Expected behavior:
Test
should be type guarded and becomeTestTwo
inside theif
statement.Actual behavior:
Test
is not type guarded after the check. It remainsTest
.Strangely enough, if
payload
is manually cast withas
to beTest
, type guarding suddenly works.So, it seems to be tighed some how to the user type guard function
isTest
.Playground Link: link
Related Issues:
Similar to the #26729, but not the same
The text was updated successfully, but these errors were encountered: