강의

멘토링

커뮤니티

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

·

348

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

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