microsoft / microsoft/TypeScript
Either understand const arrow assertions or give better errors on them
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
As mentioned by @threehams in https://github.com/microsoft/TypeScript/issues/35838#issuecomment-569832017, people are pretty confused about the rules for assertion functions, and I don't blame them. For example
const assert = (blah: unknown): asserts blah => { throw "hai"; }
let x: string | undefined;;
assert(x);
In our nightly releases, we give an elaboration on the declaration of assert like
'assert' needs an explicit type annotation.
For all intents and purposes, it looks like assert does have an annotation! The problem is that assert itself needs a : (x: unknown) => asserts x, because it's not automatically inferred from the arrow function.
We have two options:
-
Remove this restriction when the declaration of an assertion function is trivially detectable.
-
Make assertion function errors more clear for arrow functions:
'assert' needs an explicit type annotation. While the function it has been assigned to is fully annotated, the variable declaration for 'assert' does not.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リポジトリのファイルもテストも指定されていません。issue にある const arrow assertion の例を nightly TypeScript build で再現し、その後、既存の assertion-function の診断経路を調べてください。自明に検出できる arrow assertion が受け入れられるか、診断によって変数宣言自体に必要な明示的な型注釈がないことが説明されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100