microsoft / microsoft/TypeScript
Instantiation expression inside nested classes produces unexpected circular reference error
オープン
@jakebailey がすでに取り組んでいます。
2023年2月22日 から。
Needs Investigation
Rescheduled
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
instantiation expression nested class
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
class A<T = number> {
//static { type _<T extends A = A> = 0 }
//^ will work when uncomment it?
value!: T;
child!: InstanceType<typeof A.B<A<T>>>
static B = class B<T extends A = A> {
parent!: T;
}
}
var a = new A
a.child.parent.value
// ^?
🙁 Actual behavior
Shows an error 'child' is referenced directly or indirectly in its own type annotation..
However, when uncommenting // static {...} it will work only in playground.
In VSCode it still shows the error above.
🙂 Expected behavior
a.child.parent.value is number
Workaround
A workaround is remove the default type for class B<T>. The code below works well, also, only in playground. In my VSCode(5.0.0-dev.20230216) it still breaks unfortunately.
class A<T extends number = number> {
value!: T;
child!: InstanceType<typeof A.B<A<T>>>
static B = class B<T extends A> {
parent!: T;
}
}
var a = new A
a.child.parent.value
// ^? number
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
評価
この issue はまだ評価されていません。