-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Low priority inference trumps a much better inference that can be made from a generic signatureย #56931
Copy link
Copy link
Open
Labels
Domain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionRelated to type inference performed during signature resolution or `infer` type resolutionPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
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?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Domain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionRelated to type inference performed during signature resolution or `infer` type resolutionPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases