microsoft / microsoft/TypeScript
Generic function with function as argument autocomplete broken, unless generic argument of the argument function is it's first argument
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
🔎 Search Terms
typescript generic function no autocomplete function as argument
🕗 Version & Regression Information
Relevant versions are 5.4.5 and above, tested in all versions from 5.4.5 to 5.8.0 (Nightly) inclusive, I was able to reproduce the bug in all versions.
⏯ Playground Link
💻 Code
async function registerPluginBad<Opt extends Record<string, any>>(callback: (app: any, options: Opt) => void, opts: NoInfer<Opt>): Promise<void> {}
registerPluginBad((app, opts: { something: string }) => {}, {
// below autocomplete is broken, even though the type is properly validated
some
});
// interestingly, autocomplete works if "options" argument comes first, for example:
async function registerPluginGood<Opt extends Record<string, any>>(callback: (options: Opt, app: any) => void, opts: NoInfer<Opt>): Promise<void> {}
registerPluginGood((opts: { something: string }, app: any) => {}, {
// below autocomplete works
some
});
🙁 Actual behavior
This one has to be tested in the playground:
registerPluginBad - second argument does not autocomplete, however type is properly validated
registerPluginGood - exact same function, except the first argument "callback" arguments have changed the order, which for some reason fixes the autocomplete
🙂 Expected behavior
For both functions, autocomplete should work. Argument order should not matter.
Both do not infer from "opts", so any inference should be from "options" argument of the callback.
Additional information about the issue
No response
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
Open the linked TypeScript Playground and reproduce the difference between registerPluginBad and registerPluginGood. Trace the autocomplete and generic inference behavior for the callback parameter order; done means both calls provide completion for the options object while preserving type validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers, developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100