microsoft / microsoft/TypeScript
Type alias circularly references itself
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 Search Terms
circular reference, generic, error TS2456, recursive
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about circular reference
⏯ Playground Link
💻 Code
type FooType = {
foo?: boolean;
};
type BaseElement<T> = FooType & {
children: CustomElement[];
type: T;
};
type CustomElement = BaseElement<'h1'>;
🙁 Actual behavior
When defining a recursive type structure using a generic type, TypeScript incorrectly reports a Type alias 'CustomElement' circularly references itself.(2456) error, even though the type should be resolvable.
It gets weird when you move type: T; line above the children: CustomElement[]; and the error disappears. Also removing FooType will resolve the issue.
🙂 Expected behavior
In the first place the code should not throw any errors, in the second place the behavior should not change by reordering records of a type.
Additional information about the issue
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の再現から始め、ジェネリックな交差型における 2 つのメンバー順序を比較します。再帰的な型エイリアスに対する循環参照の診断を追跡し、FooType を追加するとそれが変わる理由を特定します。完了条件は、有効な再帰構造で TS2456 が報告されなくなり、メンバー順序によって結果が変わらないことです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100