microsoft / microsoft/TypeScript
Possible regression of intersection type inference in 5.7.2 compared to 5.6.3
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
🔎 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked Playground reproduction with TypeScript 5.6.3 and 5.7.2 to confirm the inference difference. Read the change in PR #52095 and trace the type-inference path involved in the example. Done means the code infers Variable<number, "x"> without the reported error while preserving the expected behavior in both versions' regression tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100