microsoft / microsoft/TypeScript
Nested inference fails if function is called inline
Open
Nobody has claimed this yet.
Domain: check: Type Inference
Possible Improvement
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
Nested inference, function call
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about nested function call inference
⏯ Playground Link
With libraries
Minimal reproduction
💻 Code
type NoInfer<T> = [T][T extends any ? 0 : never]
type ErrorFn = (error: unknown) => void
declare const genericFn: <T>(args: {
parser: (p: unknown, errorFn: ErrorFn) => T
handler: (data: { body: NoInfer<T> }) => unknown
}) => T
declare const createParser: <T>(arg: T) => (p: unknown, errorFn: ErrorFn) => NoInfer<T>;
genericFn({
parser: createParser(1 as const),
handler: ({ body: _ }) => {
// ^?
// unknown, should be 1
}
})
🙁 Actual behavior
Handler body is not inferred, becomes default of unknown.
🙂 Expected behavior
Handler body should be inferred from parser, and be 1.
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 with the linked minimal reproduction in the TypeScript Playground, then compare it with the version using libraries. Trace how the inline createParser call contributes to generic inference and verify the handler's body type. Done means the reproduced case infers body as 1 rather than unknown.
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