Type Assertions

tapata·2022년 3월 6일
0

TypeScript

목록 보기
1/1

Type Assertions

  • Less Specific 타입에서 More Specific 타입으로
  • 변수 as MoreSpecificType
  • (변수 as MoreSpecificType).method
// HTMLElement(less specific) => HTMLCanvasElement
const myElement:HTMLElement =  document.getElementById("main_canvas")
const myCanvas:HTMLCanvasElement = document.getElementById("main_canvas") as HTMLCanvasElement;

Definitive Assignment Assertion

  • key!:string
profile
hello

0개의 댓글