Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

union type property does not exist

import { is } from 'typescript-is';

...

const getText = (obj: Obj1 | Obj2): string => {
  if (is<Obj1>(obj)) {
    return obj1.message;
  }

  return obj2.text;
};
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #union #type #property #exist
ADD COMMENT
Topic
Name
1+9 =