Create type with two possible variants in Typescript -
is there way in typescript
declare variable can int16array
or uint16array
, nothing more?
typescript 1.4 has support type unions, notation is:
var arr: int16array|uint16array;
common methods both of these have available on arr
. if use instanceof
or typeof
checks on arr
in conditional/branched code, infer type of arr
in branches.
typescript 1.4. has support type aliases:
type my16array = int16array | uint16array;
you can use:
var arr: my16array;
Comments
Post a Comment