Decorator 란 ?
- 함수다.
- 컴파일 타임에는 그 함수의 타입만 체크한다.
- 런타임에 사용 및 처리가 된다.
- 클래스, 메서드, 프로퍼티, 메서드의 파라미터에 사용할 수 있다.
- 클래스가 인스턴스로 만들어질 때가 아니라, 최초 클래스가 참조될 때, 한번만 적용된다.
Decorator 코드 작성 준비
- step1. 프로젝트 생성
- mkdir ts-decorators
- cd ts-decorators
- npm init -y
- step2. typescript 설치
- step3. tsconfig 설정
- npx tsc --init
- tsconfig.json
- experimentalDecorators: true
Decorator 종류 별 예제로 알아보기
Class Decorator
Method Decorator
Property Decorator
Parameter Decorator
Decorator 참고
andreypopp/autobind-decorator