강의

멘토링

로드맵

Inflearn Community Q&A

No author

This post's author information has been deleted.

[Renewal] TypeScript All-in-One: Part 1. Basic Syntax

New features in the class

interface에 readonly 속성이 있을 때

Written on

·

350

0

interface A {
  readonly a: string;
  b: string;
}

class B implements A {
  a: string = '123'; // OK
  b: string = 'world';
}

const b: B = new B(); 
b.a = '456'; // OK

console.log(b); // { a: '456', b: 'world' }

 

인터페이스 A에서 변수 a는 readonly 키워드가 붙어있는데 이를 구현한 클래스 B에서 readonly 키워드를 붙여주지 않아도 에러가 발생하지 않는 이유가 궁금합니다.

 

interfacetypescriptclass

Quiz

TypeScript의 주된 목적은 무엇일까요?

자바스크립트 코드 실행 속도 향상

브라우저 호환성 자동 해결

변수, 매개변수, 리턴값에 타입을 부여하여 안정성 확보

CSS 스타일 자동 생성

Answer 1

1

zerocho님의 프로필 이미지
zerocho
Instructor

타입스크립트가 그렇게 만들어졌기 때문입니다. readonly에 관한 논쟁이 많습니다.

https://github.com/microsoft/TypeScript/issues/13002

No author

This post's author information has been deleted.

Ask a question