로딩
요청 처리 중입니다...

[TypeScript] 타입스크립트 어썰션(Assertion)

 [TypeScript] 타입스크립트 어썰션(Assertion)

어썰션(Assertion) 아래와 같이 "HTMLCanvasElement"와 같은 수동으로 타입을 명시할때 어썰션(Assertion)을 사용할 수 있다. const myCanvas = document.getElementById('main_canvas') as HTMLCanvasElement; 꺽쇠 괄호()를 이용하여 표현해줄 수도 있다. 다만, ".tsx"에서는 동작하지 않는다. const myCanvasAngleBracket = document.getElementById('main_canvas'); 어썰션(Assertion)은 타입의 특정성을 조절하는데에만 쓸 수 있다. const x = 'hello' as number; // Conversion of type 'string' to type 'number' maybe a mistake // because neither type sufficiently overlaps with the other. ...

# as # assertion # type # typescript # 어썰션 # 타입 # 타입스크립트