Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typescript `is a` function determine type

type Fish = { swim: () => void }
type Bird = { fly: () => void }
function isFish(pet: Fish | Bird): pet is Fish {
  return (pet as Fish).swim !== undefined;
}

const myFish = { swim: () => {} }

if(isFish(myFish)){
  myFish.swim()
}
Source by www.typescriptlang.org #
 
PREVIOUS NEXT
Tagged: #typescript #function #determine #type
ADD COMMENT
Topic
Name
3+5 =