microsoft / microsoft/TypeScript
Low priority inference trumps a much better inference that can be made from a generic signature
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
inference generic signature type parameters low priority
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
declare function defineComponent<Props extends Record<string, any>>(
setup: (props: Props) => void,
options?: {
props?: (keyof Props)[];
},
): (props: Props) => unknown;
const res1 = defineComponent(
<T extends string>(_props: { msg: T }) => {
return () => {};
}
);
res1
// ^? const res1: <T extends string>(props: { msg: T; }) => unknown
const res2 = defineComponent(
<T extends string>(_props: { msg: T }) => {
return () => {};
},
{
props: ["msg"],
},
);
res2
// ^? const res2: (props: { msg: any; }) => unknown
🙁 Actual behavior
A low-priority inference made from keyof Props prevents inference from the generic signature
🙂 Expected behavior
I'd expect both of those to infer the same result: <T extends string>(props: { msg: T; }) => unknown
Additional information about the issue
There is an existential question to be asked here... what is a low-priority inference in the first place? :P Where is the line? Should every inference priority other than InferencePriority.None be treated as low-priority here?
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
Reproduce the inference difference in the linked TypeScript Playground, starting with the generic signature and the keyof Props inference path described in the issue. Trace how low-priority inference is handled, then verify that res2 infers the same generic signature as res1 without regressing related inference cases.
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
- 35/100