---
title: "Discussion on \"TypeScript - 型別斷言(Type Assertion)\" | Hashnode"
description: "Discussion on \"TypeScript - 型別斷言(Type Assertion)\". 型別斷言是 TypScript 的一種機制，允許我們手動指定一個明確的型別，提供 TypeScript 編譯器無法自行推斷的額外型別資訊。\n我們可以透過這兩種寫法來指定型別斷言：\n語法\n尖括號 <>（angle-bracket）語法\n語法：<type>value - 在需要斷言的變數前加上 <Type> 即可\n const myCanvas = <HTMLCanvasElement>document.getElementById(\"main_canvas\")\n\nas 語法\n語法：value as..."
url: "https://hashnode.com/posts/typescript-type-assertion/652c399ec75b59c2c06e4929"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [TypeScript - 型別斷言(Type Assertion)](https://yachuh.hashnode.dev/typescript-type-assertion?utm_source=hashnode&utm_medium=feed)

型別斷言是 TypScript 的一種機制，允許我們手動指定一個明確的型別，提供 TypeScript 編譯器無法自行推斷的額外型別資訊。 我們可以透過這兩種寫法來指定型別斷言： 語法 尖括號 <>（angle-bracket）語法 語法：<type>value - 在需要斷言的變數前加上 <Type> 即可 const myCanvas = <HTMLCanvasElement>document.getElementById("main\_canvas") as 語法 語法：value as...

Oct 15, 2023 · 2 min read · yachuh.hashnode.dev  
Read the article

-   [#typescript](https://hashnode.com/tag/typescript)

## Written by

[Ya Chu](https://hashnode.com/@yachuh)

@yachuh

  
[View profile](https://hashnode.com/@yachuh)

Embarking on the Frontend Development Journey

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
