microsoft / microsoft/TypeScript
Possible regression of intersection type inference in 5.7.2 compared to 5.6.3
オープン
まだ誰も着手していません。
Domain: check: Type Inference
Help Wanted
Possible Improvement
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
inference generic types
🕗 Version & Regression Information
- This changed between versions 5.6.3 and 5.7.2
- This changed in commit or PR https://github.com/microsoft/TypeScript/pull/52095
⏯ Playground Link
💻 Code
class Variable<U, S extends string> {
constructor(public s: S) { }
u!: U;
}
function mkGeneric<U, S extends string>(s: S) {
return new Variable<U, S>(s)
}
type ExactArgNames<GenericType, Constraint> = GenericType & {
[K in keyof GenericType]: K extends keyof Constraint ? GenericType[K] : never
}
type AllowVariables<T> = Variable<T, any> | { [K in keyof T]: Variable<T[K], any> | T[K] }
type TestArgs = {
someArg: number
}
type TestArgsWithVars = AllowVariables<TestArgs>
function takesGeneric<V extends AllowVariables<TestArgs>>(a: ExactArgNames<V, TestArgs>): void {
}
let v = takesGeneric({someArg: mkGeneric("x")});
🙁 Actual behavior
VVersion 5.7.2 of the compiler infers the variable type as Variable<uknown, "x"> and subsequently generates an error
🙂 Expected behavior
VVersion 5.6.3 of the compiler infers the variable type correctly as Variable<number, "x">
Additional information about the issue
This is breaking most code that uses typed-graphql-builder https://github.com/typed-graphql-builder/typed-graphql-builder/issues/85
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンクされた Playground の再現を TypeScript 5.6.3 と 5.7.2 で実行し、推論の違いを確認します。PR #52095 の変更を読み、例に関係する型推論の経路を追跡します。コードが報告されたエラーなしで Variable<number, "x"> を推論し、両バージョンの回帰テストで期待される動作を維持できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100