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 have this situation and no means to meaningful change the data structure. So I cannot add a tag.
Is there a way to distinguish the types without a tag? I tried ducktyping, but it does not work. See my example
type Result = Done | Error; // a disjoint union type with two cases
type Done = { count: number }
type Error = { message: string }
const doSomethingWithDone = (obj: Done) => {/*...*/}
const doSomethingWithError = (obj: Error) => {/*...*/}
const f = (result: Result) => {
if (result.count) {
doSomethingWithDone(result)
} else {
doSomethingWithError(result)
}
}
The text was updated successfully, but these errors were encountered:
It does make sense, since your typings don't say that a Done cannot have a count property.
Using exact objects types seems to partially work, in the sense that it does refine properly, as you can see in this example. Sadly, you also have to do an explicit check in the else.
I have this situation and no means to meaningful change the data structure. So I cannot add a tag.
Is there a way to distinguish the types without a tag? I tried ducktyping, but it does not work. See my example
The text was updated successfully, but these errors were encountered: