Bug Report
🔎 Search Terms
- predicate
- type predicate
- type predicate return
🕗 Version & Regression Information
- This is NOT a crash
- This changed between versions ______ and _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
Playground link with relevant code
💻 Code
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?
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The call to
getWingspanshows an error sayingArgument of type 'Animal' is not assignable to parameter of type 'Bird'.🙂 Expected behavior
The function
isAnimalOfTypealready asserts that the Animal will be of type T. So, why doesisBirdnot automatically assert that?