-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect overload is used for pipe
when first function has optional parameter
#29913
Comments
The first overload that matches is always chosen. The |
How come this behaviour only applies when This is the order of overloads used by Lodash's |
|
If we do this, it fixes the example above, but it causes other issues: {
declare const pipe: {
// 1-argument first function
<A, B>(ab: (a: A) => B): (a: A) => B;
// 0-argument first function
// Workaround: disable this overload
<A>(a: () => A): () => A;
};
// Expected and actual type: `(a: {} | undefined) => number`
const fn1 = pipe((_a?: {}) => 1);
// Expected type: () => number
// Actual type: (a: unknown) => number
const fn2 = pipe(() => 1);
} Workaround: use generic rest parameters: {
declare const pipe: {
<A extends any[], B>(ab: (...a: A) => B): (...a: A) => B;
};
// Expected and actual type: `(a: {} | undefined) => number`
const fn1 = pipe((_a?: {}) => 1);
// Expected and actual type: () => number
const fn2 = pipe(() => 1);
} |
TypeScript Version: 3.3.1
Search Terms:
Code
strictFunctionTypes
is disabledpipe
overload is zero parameters for first functionRelated Issues:
#29904
The text was updated successfully, but these errors were encountered: