로딩
요청 처리 중입니다...

[TypeScript] Type and Validation

 [TypeScript] Type and Validation

null, undefined 할당 null과 undefined도 데이터 타입이며, string 타입으로만 설정된 변수에 null 혹은 undefined를 할당할 경우 에러를 반환합니다. string | null 혹은 string | undefined 타입으로 서브타입을 지정해 주어야 할당 가능합니다. tsconfig.json에 기본적으로 null과 undefined을 서브타입으로 지정해주는 설정이 있습니다. "strictNullChecks"를 false로 설정하게 되면 null과 undefined를 서브타입으로 기본 지정해줍니다.

기본값은 true입니다. // strictNullChecks: true const name: string = null; // Type 'null' is not assignable to type 'string'. const name2: string | null = null; const name3: string = undefinded; // Type 'unde...