Skip to Content
러닝 타입스크립트
book

러닝 타입스크립트

by 조시 골드버그, 고승원
January 2023
Beginner to intermediate
372 pages
8h 47m
Korean
Hanbit Media, Inc.
Content preview from 러닝 타입스크립트
75
3
유니언과 리터럴
값이 할당되기 전에 속성 중 하나에 접근하려는 것처럼 해당 변수를 사용하려고 시도하면 다음
과 같은 오류 메시지가 나타납니다.
let mathematician: string;
mathematician?.length;
//~~~~~~~~~~~//~~~~~~~~~~~
// Error: Variable 'mathematician' is used before being assigned.// Error: Variable 'mathematician' is used before being assigned.
mathematician = "Mark Goldberg";
mathematician.length; // Ok
변수 타입에
undefined
가 포함되어 있는 경우에는 오류가 보고되지 않습니다. 변수 타입에
|
undefined
를 추가하면,
undefined
는 유효한 타입이기 때문에 사용 전에는 정의할 필요가
없음을 타입스크립트에 나타냅니다.
이전 코드 스니펫에서
mathematician
의 타입이
string
|
undefined
이면 어떤 오류도 발생
하지 않습니다.
let mathematician: string | undefined;
mathematician?.length; // Ok
mathematician = "Mark Goldberg";
mathematician.length; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

이펙티브 타입스크립트

이펙티브 타입스크립트

Dan Vanderkam
견고한 데이터 엔지니어링

견고한 데이터 엔지니어링

조 라이스, 맷 하우슬리
파이썬으로 살펴보는 아키텍처 패턴

파이썬으로 살펴보는 아키텍처 패턴

오현석, 해리 퍼시벌, 밥 그레고리

Publisher Resources

ISBN: 9791169210638