Microsoft/TypeScript
GitHub ã§èŠãPossible regression of intersection type inference in 5.7.2 compared to 5.6.3
Open
#60,864 opened on 2024幎12æ27æ¥
Domain: check: Type InferenceHelp WantedPossible Improvement
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð 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