6.3 타입 단언
타입 단언을 통해 컴파일러에게 특정 타입 정보의 사용을 강제할 수 있다.
Last updated
(3 as any).substr(0, 3);const wowSuchAny = (((42 as any) as any) as any) as any);interface Dog {
legs: 4;
bark(): void;
}
interface Insect {
legs: number;
creepy: boolean;
}
const dog: Dog = { legs: 4, bark() { console.log('bark') } };
const insect: Insect = dog as Insect;
// error TS2352: Type 'Dog' cannot be converted to type 'Insect'.
// Property 'creepy' is missing in type 'Dog'.const insect2: Insect = (dog as any) as Insect; // ok