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 we initialize the all, we explicitly give it the type All (even tho we assign an AB to it), and when we hover on it, it shows that its type is All.
But, when we check it with the predicate function (isCD), it looks like that it tries to compare the AB type instead of the All, and its result will be never since AB and CD has no overlap.
The text was updated successfully, but these errors were encountered:
This is working as intended. Assignment narrows, the compiler can see that all can possibly only be A or B, so after checking both with your predicate the resulting type is never.
You can avoid the narrowing upon assignment using a type assertion: const all: All = ab as All;
Yep, your right. The error on my code is actually caused because the assignment itself that does not narrowed correctly inside the while loop, but that's another bug, so it can be closed
π Search Terms
predicate
π Version & Regression Information
It worked till version version
5.4.5
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.8.3#code/JYOwLgpgTgZghgYwgAgILIN4FgBQBIMATwAcIAuZAIjkoG5cBfXXUSWRFAIU1wJPKoAjOo2Y5W0eEmQBhHviKkKlBCJxMcLcJI7IAIvL5KqAEzUbcilKm4BeNMgA+yTvU04rsg-bnO9by340ABtg5HsbJy8AnAQAexAAZzBkOEEKSPsAWTgwAAsAOig4EBM4gFsACgBKZAA+ZAAGAoBWZAB+TGQrZRpkBmQKDG7+ZWF+mPiklLhQjNDw1MFJhOTkYESZb2RK2eD54NrbBux8KAgwAFcoEFTQgs9bJ6pVJ2c9h6Cn+0ozNwYYsAYDsNltdqFqrVTng9rRkAB6eFoBBXWYUEAQABu0AANMgAKIAD1IKIgJgoW1EOCAA
π» Code
π Actual behavior
all
's type isnever
inside the if statementπ Expected behavior
all
's type should beCD
inside the if statementAdditional information about the issue
When we initialize the
all
, we explicitly give it the typeAll
(even tho we assign anAB
to it), and when we hover on it, it shows that its type isAll
.But, when we check it with the predicate function (
isCD
), it looks like that it tries to compare theAB
type instead of theAll
, and its result will benever
sinceAB
andCD
has no overlap.The text was updated successfully, but these errors were encountered: