Generic indexed access on a substitution type with an array constraint resolves incorrectly
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- typescript
- 領域
- compilers
調査の方向性
リンクされている TypeScript Playground の再現コードから始め、失敗するジェネリックなインデックスアクセス分岐と、配列型エイリアスを追加した動作するバリアントを比較します。PR 48837 で説明されている挙動を読み、そのうえで、元の例が制約エラーを報告しなくなり、期待される推論された mapped type の挙動が維持されていることを確認します。
索引モデルが issue の本文から書いたものです。
説明
🔎 Search Terms
indexed access substitution type array constraint
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type LiteralType = string | number | boolean;
type ValueGetter<ValueType extends LiteralType = LiteralType> = () => ValueType;
type Schema = SchemaArray | SchemaObject | LiteralType;
type SchemaArray = Array<SchemaObject | SchemaArray | LiteralType>;
type SchemaObject = {
[key: string]: SchemaObject | SchemaArray | LiteralType;
};
type InferValuesFromSchema<S extends Schema> = S extends LiteralType
? ValueGetter<S>
: S extends SchemaArray
? {
[K in keyof S]: InferValuesFromSchema<S[K]>;
}
: S extends SchemaObject
? {
[K in keyof S]: InferValuesFromSchema<S[K]>;
}
: never;
🙁 Actual behavior
an error is reported:
Type 'S[K]' does not satisfy the constraint 'Schema'.
Type 'S[keyof S]' is not assignable to type 'Schema'.
Type 'S[string] | S[number] | S[symbol]' is not assignable to type 'Schema'.
Type 'S[string]' is not assignable to type 'Schema'.
Type 'S[string]' is not assignable to type 'SchemaObject'.
Type 'S[keyof S]' is not assignable to type 'SchemaObject'.
Type 'S[K]' is not assignable to type 'SchemaObject'.
Type 'S[keyof S]' is not assignable to type 'SchemaObject'.
Type 'S[string] | S[number] | S[symbol]' is not assignable to type 'SchemaObject'.
Type 'S[string]' is not assignable to type 'SchemaObject'.(2344)
🙂 Expected behavior
There should be no error, S[K] should satisfy Schema constraint (at least since https://github.com/microsoft/TypeScript/pull/48837 )
Additional information about the issue
A variant with an additional type alias for that array branch works OK: TS playground.
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 106
コントリビューションガイド
はじめの一歩
- 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
-
Type/Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
OpenNSW/nsw-srilanka#497 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
milvus-io/birdwatcher#545 ·
-
kind/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
kubernetes-sigs/prow#953 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
caddyserver/caddy#8046 ·