TypeScript union Type

kukudas·2022년 2월 7일
0

TypeScript

목록 보기
3/39

Introduction to TypeScript union type

let result: number | string;
result = 10; // OK
result = 'Hi'; // also OK
result = false; // a boolean value, not OK

위 처럼 union type으로 변수가 여러개의 type중 하나를 가질 수 있게됨.

union type으로 변수에 하나 이상의 tpye을 지정할 수 있음.

출처

0개의 댓글

관련 채용 정보