interface Book {
name: string
}
function greet(this: Book, msg: string) {
return `${this.name}, ${msg}`
}
TS 에서 this타입을 정의할 때 함수의 첫번째 인자로 this를 넣으면 this는 예약어이기 때문에 매개변수 중 하나로 인식을 안하고 this의 타입을 설정할 수 있다.
'Javascript > Typescript' 카테고리의 다른 글
[Typescript] abstract class (0) | 2023.11.13 |
---|---|
[Typescript] 함수 오버로딩 (0) | 2023.11.12 |
[Typescript] 인덱스 시그니처 (0) | 2023.11.12 |
[Typescript] class 타입과 생성 시그니처 (0) | 2023.11.12 |
[Typescript] Interface, type 차이 (0) | 2023.11.12 |
댓글