`asserts this is T` does not narrow type of `this`
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- typescript
- 領域
- compilers
調査の方向性
リンクされた TypeScript Playground の再現コードから始め、test1 のメソッド呼び出しのケースと test2 のスタンドアロンのアサーションを比較します。メンバー呼び出し後に asserts this is A がどのように処理されるかを追跡し、次に、メソッド呼び出しによって c が絞り込まれ、スタンドアロンのケースを後退させることなく onlyDefinedInA() が受け入れられることを確認します。
索引モデルが issue の本文から書いたものです。
説明
🔎 Search Terms
asserts this is Tnarrowassertions- I also checked #59707, but it is unrelated (generic types).
🕗 Version & Regression Information
- Playground:
v5.7.0-dev.20241004 - At least since
v5.6.2
⏯ Playground Link
💻 Code
class A {
onlyDefinedInA() {
console.log("A");
}
assertA(): asserts this is A { }
}
class B {
assertA(): asserts this is A { }
}
type C = A | B;
function assertA(c: C): asserts c is A {
}
function test1(c: C) {
c.assertA();
c.onlyDefinedInA(); // Error: Property 'onlyDefinedInA' does not exist on type 'C'. Property 'onlyDefinedInA' does not exist on type 'B'.
}
function test2(c: C) {
assertA(c);
c.onlyDefinedInA(); // Works!
}
🙁 Actual behavior
Type of c is not narrowed after the method call, producing an error.
🙂 Expected behavior
I expect the member function to to perform type narrowing.
Additional information about the issue
No response
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/TypeScript のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
microsoft/TypeScript#64322 · コメント 2 件 · リアクション 1 件 · 担当者 2 名 ·
-
Possible Improvement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/TypeScript#64278 · コメント 1 件 · リアクション 1 件 ·
-
Docs
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
microsoft/TypeScript#64118 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
microsoft/TypeScript#64094 ·
-
Docs
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
microsoft/TypeScript#63959 · コメント 5 件 ·
microsoft/TypeScript の issue をすべて見る
似ている issue
-
optimization optimization:agents-md-curator
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
githubnext/gh-aw-cao#13143 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
blinklabs-io/bursa#904 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · コメント 2 件 ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100