microsoft / microsoft/TypeScript
Reverse mapped type inference fails to infer from annotated parameters in partially-inferrable object types
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
reverse mapped inference annotated parameters partially inferrable noninferrable object context sensitive
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
declare function setup<TGuards>(_: {
guards: {
[K in keyof TGuards]: (ctx: unknown, params: TGuards[K]) => boolean;
};
}): TGuards;
const guards = setup({
guards: {
a: () => true,
b: (_, params) => true,
c: (_, params: number) => true,
},
});
guards
// ^? const guards: { a: unknown; b: unknown; c: unknown; }
🙁 Actual behavior
It infers { a: unknown; b: unknown; c: unknown; }
🙂 Expected behavior
I'd expect { a: unknown; b: unknown; c: number; } to get inferred here
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
Start by reproducing the annotated-parameter example in the linked TypeScript Playground and compare the actual and expected inferred types. The issue names no repository file or regression test, so the relevant reverse mapped type inference implementation and a suitable compiler test will need to be located; done means the example infers c as number while a and b remain unknown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100