KSCOLD LogoKSCOLD
Blog
Feed
Product
Admin Night
Vault
Guestbook
Info

Vault 목록

private

연결된 노트와 함께 읽기

private

2024년 8월 31일
  • private는 해당 클래스(class)의 인스턴스(Instance)에서만 접근 가능하다.
TypeScript
class Hello { constructor(private name: string) {} } const hello = new Hello('kmj') hello.name // Property 'name' is private and only accessible within class 'Hello'.
  • 위의 예시에서 name을 가져오려하려면, 위와 같은 에러가 뜬다.
  • 그리고 서브클래스(자식 클래스)에서 name을 public으로 바꾸어주려고 해도 에러가 뜬다.
TypeScript

Synapse Map Insight

class Hi extends Hello { constructor(public name: string) { super(name) } // Class 'Hi' incorrectly extends base class 'Hello'. // Property 'name' is private in type 'Hello' but not in type 'Hi'.ts(2415) }