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
interfaceAnimal{name: string;}interfaceBirdextendsAnimal{wingSpan: string;}/** * Asserts that an animal is of type T if condition is true for that animal. */functionisAnimalOfType<TextendsAnimal>(animal: Animal,condition: (animal: T)=>boolean): animal is T{returncondition(animalasT);}functionisBird(animal: Animal){returnisAnimalOfType<Bird>(animal,(bird)=>Boolean(bird.wingSpan));}functiongetWingspan(bird: Bird){returnbird.wingSpan;}constanimals=[{name: "a"},{name: "a",wings: "3ft"}]asAnimal[];functioncheckAnimals(animals: Animal[]){returnanimals.map(animal=>{console.log(animal);if(isBird(animal)){console.log(getWingspan(animal));}})}
🙁 Actual behavior
The call to getWingspan shows an error saying Argument of type 'Animal' is not assignable to parameter of type 'Bird'.
🙂 Expected behavior
The function isAnimalOfType already asserts that the Animal will be of type T. So, why does isBird not automatically assert that?
The text was updated successfully, but these errors were encountered:
This was marked as a duplicate of #10734, which was closed by #57465. But that PR only let "identifier" type predicates flow, not assertion predicates. The example in this issue is still broken.
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The call to
getWingspan
shows an error sayingArgument of type 'Animal' is not assignable to parameter of type 'Bird'
.🙂 Expected behavior
The function
isAnimalOfType
already asserts that the Animal will be of type T. So, why doesisBird
not automatically assert that?The text was updated successfully, but these errors were encountered: