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

러닝 타입스크립트

by 조시 골드버그, 고승원
January 2023
Beginner to intermediate
372 pages
8h 47m
Korean
Hanbit Media, Inc.
Content preview from 러닝 타입스크립트
153
8
클래스
이 장의 뒷부분에서 하위 클래스
subclass
와 관련된 생성자를 살펴봅니다.
8.2
클래스 속성클래스 속성
타입스크립트에서 클래스의 속성을 읽거나 쓰려면 클래스에 명시적으로 선언해야 합니다. 클
래스 속성은 인터페이스와 동일한 구문을 사용해 선언합니다. 클래스 속성 이름 뒤에는 선택적
으로 타입 애너테이션이 붙습니다.
타입스크립트는 생성자 내의 할당에 대해서 그 멤버가 클래스에 존재하는 멤버인지 추론하려
고 시도하지 않습니다.
다음 예제에서
destination
string
으로 명시적으로 선언되어 있어
FieldTrip
클래스 인
스턴스에 할당되고 접근할 수 있습니다. 클래스가
nonexistent
속성을 선언하지 않았기 때문
에 생성자에서
this
.
nonexistent
할당은 허용되지 않습니다.
class FieldTrip {
destination: string;
constructor(destination: string) {
this.destination = destination; // Ok
console.log('We're going to ${this.destination}!');
this.nonexistent = destination;
// ~~~~~~~~~~~// ~~~~~~~~~~~
// Error: Property 'nonexistent' ...
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