Issue
Hey I'm trying to differentiate between two equivalent types:
type A = {
a: string
}
type B = {
a: string
}
With two type predicates:
function isA(obj: any): obj is A {
return true
}
function isB(obj: any): obj is B {
return true
}
But I'm facing an issue where each predicate catches both types when applied to a union type.
Here is an example: Playground Link
Is this the intentional behavior? and if so, what is the use case?
Solution
I ended up just casting to any
before the if
, just like the ts playground link I have in the question.
This way I have the union type outside the if
and the wanted type inside the if
Answered By - CY-OD
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.