-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 resolutionHelp WantedYou can do thisYou can do thisPossible 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
generic function spread regression inference
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics
⏯ Playground Link
💻 Code
export type Node = { };
declare function fooooooo<T, Result extends ArrayLike<unknown>, Evil extends readonly unknown[]>(
input: T,
callback: (input: T, prev: Result, ...evil: Evil) => Result,
): Result
declare function baaaaaar<T, Result extends ArrayLike<unknown>>(
input: T,
callback: (input: T, prev: Result) => Result,
): Result
declare function callback<T>(
input: T,
prev: string[],
): string[];
export function example<T>(input: T) {
// Infers type parameter Result correctly
fooooooo(input, callback);
// ^? function fooooooo<T, string[], []>(input: T…
// Fails to infer type parameter Result correctly instead infers the constraint
baaaaaar(input, callback);
// ^? function baaaaaar<T, ArrayLike<unknown>>(in…
// Bypassing inference, the function call is correct
baaaaaar<T, string[]>(input, callback);
// Infers type parameter Result correctly
baaaaaar(input, callback<T>);
// ^? function baaaaaar<T, string[]>(input: T, ca…
}🙁 Actual behavior
baaaaaar(input, callback) infers the constraint of Result = ArrayLike<unknown>
🙂 Expected behavior
baaaaaar(input, callback) should infer Result = string[] from the return type or parameter of callback.
Additional information about the issue
No response
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 resolutionHelp WantedYou can do thisYou can do thisPossible 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