Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

typescript type guard function

type Fish = { swim: () => void };
type Bird = { fly: () => void };

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

const myFish: Fish | Bird = { swim: () => {} };

isFish(myFish) && myFish.swim();
Comment

PREVIOUS NEXT
Code Example
Typescript :: reduce an array of objects to string 
Typescript :: is id in array typescript 
Typescript :: NASDAQ: TSLA 
Typescript :: typescript for 
Typescript :: get local storage data in angular 
Typescript :: typescript declare dictionary type 
Typescript :: circle dot in latex 
Typescript :: window open blob 
Typescript :: combine two lists c# 
Typescript :: peer of typescript@=2.8.0 
Typescript :: Material-ui icon npm 
Typescript :: angular get url params 
Typescript :: how to compile typescript 
Typescript :: typescript throw not implemented exception 
Typescript :: contents of file to variable python 
Typescript :: mat-form-field email validation 
Typescript :: recharts bar chart 
Typescript :: map typescript 
Typescript :: react typescript props 
Typescript :: Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories. 
Typescript :: how to check is null or empty in typescript 
Typescript :: typscript node-ts with nodemon 
Typescript :: whats my country 
Typescript :: how to append to a list of lists in python 
Typescript :: python requests use proxy 
Typescript :: sockjs-node/info?t=net::ERR_CONNECTION_TIMED_OUT 
Typescript :: locking value of cell 
Typescript :: typescript declare process.env 
Typescript :: state in react typescript 
Typescript :: type script array declaration 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =