명시적 this
this 타입을 지정해 주지 않으면 자동으로 any가 됨
typescript에서는 any를 지양해야 함
interface Cat {
name : string
age : number
}
const cat : Cat ={
name : 'kitty',
age : 3
}
function hello(this: Cat, message : string) {
console.log(`Hello ${this.name}, ${message}`)
}
hello.call(cat, 'You are sooooo cute!');
오버로딩
function add(a:string, b:string) : string //타입 선언
function add(a:number, b:number) : number //타입 선언
function add(a:any, b:any) { //함수 구현
return a + b
}
'FE > Typescipt' 카테고리의 다른 글
[Typescript] tsconfing.json 구성 옵션 (0) | 2023.09.01 |
---|---|
[Typescript] Generic (0) | 2023.09.01 |
[Typescript] Class (0) | 2023.09.01 |
[Typescript] Interface (0) | 2023.09.01 |
[Typescript] Type (0) | 2023.09.01 |