Open
Description
urlString
narrows the type to string
, which is correct, but it also narrows the type to non-string types in the else
clause.
It is wrong type assertion as the value can be non-url strings.
Notice that TypeScript not only knows that pet is a Fish in the if branch; it also knows that in the else branch, you don’t have a Fish, so you must have a Bird.
https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
Lines 755 to 766 in e097645
Metadata
Metadata
Assignees
Labels
No labels