Aliases

kukudas·2022년 2월 7일
0

TypeScript

목록 보기
4/39

Introduction to TypeScript type aliases

type alias로 이미 존재하는 type에 대해 새로운 이름을 붙여줄 수 있음.
syntax는 아래와 같음.

type alias = existingType;

아래는 string type에 char라는 이름 붙여서 사용함.

type chars = string;
let messsage: chars; // same as string type

union type에 alias 사용하면 편함.

type alphanumeric = string | number;
let input: alphanumeric;
input = 100; // valid
input = 'Hi'; // valid
input = false; // Compiler error
type alphanumeric = string | number;
let input: alphanumeric;
input = 100; // valid
input = 'Hi'; // valid
input = false; // Compiler error

type alias로 type에 다른 이름 붙여서 사용할 수 있음

출처

0개의 댓글

관련 채용 정보