microsoft / microsoft/TypeScript

Docs: "Type assertion" vs "asserts" keyword

未關閉
#35,653 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

Discussion
主要語言
Go
星號
111k
分支
14.3k
平均合併
2 天 4 小時
30 天內合併 PR
132

描述

Hey there!

I’m updating Programming TypeScript to include assertions in control flow analysis, and was looking for guidance about naming.

Type assertions (x as T) and assertions in control flow analysis (asserts x is T) are similarly named. What’s a good way to call these these features, in a way that doesn’t confuse people and aligns with the way the TS team is communicating it?

A couple of ideas:

  1. Rename x as T to “type coercion” or “type casting" (even though it’s not a runtime behavior), and call asserts x is T a “type assertion”
  2. Keep x as T as-is (“type assertion”), and call asserts x is T a “user-defined type assertion”, similar to a “user-defined type guard”

Thanks!

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先審閱連結的 pull request 32695,以及 issue 中關於 x as Tasserts x is T 的討論。達成一項與 TypeScript 的溝通方式一致、並能指導 Programming TypeScript 更新的統一命名慣例,即視為完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
typescript
領域
documentation
Issue 類型
文件
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。