-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
[lodash] Fix _.partial() with 3 arity func and full args #69561
[lodash] Fix _.partial() with 3 arity func and full args #69561
Conversation
@YuseiUeno Thank you for submitting this PR! This is a live comment which I will keep updated. 1 package in this PRCode ReviewsBecause this is a widely-used package, a DT maintainer will need to review it before it can be merged. You can test the changes of this PR in the Playground. Status
All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 69561,
"author": "YuseiUeno",
"headCommitOid": "d293cb430e2778a9f2446ddd07e7f6eb8f967cba",
"mergeBaseOid": "18753976aad3956a963c3cafeeab6755b7c879a3",
"lastPushDate": "2024-05-10T05:14:18.000Z",
"lastActivityDate": "2024-05-16T14:07:23.000Z",
"mergeOfferDate": "2024-05-16T14:02:52.000Z",
"mergeRequestDate": "2024-05-16T14:07:23.000Z",
"mergeRequestUser": "YuseiUeno",
"hasMergeConflict": false,
"isFirstContribution": false,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "lodash",
"kind": "edit",
"files": [
{
"path": "types/lodash/common/function.d.ts",
"kind": "definition"
},
{
"path": "types/lodash/lodash-tests.ts",
"kind": "test"
}
],
"owners": [
"bczengel",
"chrootsu",
"aj-r",
"e-cloud",
"thorn0",
"jtmthf",
"DomiR",
"WilliamChelman"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "sandersn",
"date": "2024-05-16T14:02:15.000Z",
"isMaintainer": true
},
{
"type": "approved",
"reviewer": "aj-r",
"date": "2024-05-13T10:49:50.000Z",
"isMaintainer": false
}
],
"mainBotCommentID": 2103880510,
"ciResult": "pass"
} |
🔔 @bczengel @chrootsu @aj-r @e-cloud @thorn0 @jtmthf @DomiR @WilliamChelman — please review this PR in the next few days. Be sure to explicitly select |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this change is necessary. When I test your example, it works as expected: https://stackblitz.com/edit/typescript-lodash-playground-1tpr1g?file=index.ts. In that code, p3
has type Function0<string>
as expected.
Perhaps the issue is that your f3
has multiple overloads with different numbers of arguments? If so, you probably want to avoid partial
since its behavior will be ambiguous.
Thanks for adding the missing tests though - optionally you could just revert the change to function.d.ts
and sumbit the new tests.
@@ -655,7 +655,6 @@ declare module "../index" { | |||
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: __, plc2: __, arg3: T3): Function3<T1, T2, T4, R>; | |||
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: __, arg3: T3): Function2<T2, T4, R>; | |||
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: __, arg2: T2, arg3: T3): Function2<T1, T4, R>; | |||
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, arg3: T3): Function1<T4, R>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be working as intended. I don't think it should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for checking my code!
Really?
It looks not working with pnpm test
.
❯ git --no-pager diff --cached
diff --git a/types/lodash/common/function.d.ts b/types/lodash/common/function.d.ts
index 46ac3b3746..7628278464 100644
--- a/types/lodash/common/function.d.ts
+++ b/types/lodash/common/function.d.ts
@@ -655,6 +655,7 @@ declare module "../index" {
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: __, plc2: __, arg3: T3): Function3<T1, T2, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: __, arg3: T3): Function2<T2, T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: __, arg2: T2, arg3: T3): Function2<T1, T4, R>;
+ <T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, arg3: T3): Function1<T4, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: __, plc2: __, plc3: __, arg4: T4): Function3<T1, T2, T3, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: __, plc3: __, arg4: T4): Function2<T2, T3, R>;
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: __, arg2: T2, plc3: __, arg4: T4): Function2<T1, T3, R>;
❯ pnpm -w run test lodash
> definitely-typed@0.0.3 test /Users/yusei/Workspace/repos/github.com/DefinitelyTyped/DefinitelyTyped
> node --enable-source-maps node_modules/@definitelytyped/dtslint/ types "lodash"
dtslint@0.2.20
Error:
/Users/yusei/Workspace/repos/github.com/DefinitelyTyped/DefinitelyTyped/types/lodash/lodash-tests.ts
7304:5 error TypeScript@4.7, 4.8, 4.9, 5.0, 5.1, 5.2, 5.3, 5.4, 5.5 expected type to be:
() => number
got:
Function1<unknown, number> @definitelytyped/expect
✖ 1 problem (1 error, 0 warnings)
at combineErrorsAndWarnings (/Users/yusei/Workspace/repos/github.com/DefinitelyTyped/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.20_typescript@5.5.0-dev.20240509/node_modules/@definitelytyped/dtslint/src/index.ts:259:26)
at runTests (/Users/yusei/Workspace/repos/github.com/DefinitelyTyped/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.20_typescript@5.5.0-dev.20240509/node_modules/@definitelytyped/dtslint/src/index.ts:250:18)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at main (/Users/yusei/Workspace/repos/github.com/DefinitelyTyped/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.20_typescript@5.5.0-dev.20240509/node_modules/@definitelytyped/dtslint/src/index.ts:103:22)
ELIFECYCLE Test failed. See above for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this pattern is followed here so I delete it.
This pattern
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, arg3: T3): Function1<T4, R>;
follow by
<TS extends any[], T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4): (...ts: TS) => R; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check works as not expected:https://stackblitz.com/edit/fjjtuv?file=index.ts
May be your stackblitz dependency is too old.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah I missed the overload below which does this. Thanks!
_.partial(func3) // $ExpectType (arg1: number, arg2: string, arg3: boolean) => number | ||
_.partial(func3, 42) // $ExpectType (arg2: string, arg3: boolean) => number | ||
_.partial(func3, 42, _, true) // $ExpectType Function1<string, number>; | ||
_.partial(func3, 42, "foo", true) // $ExpectType () => number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test essentially passes even without your changes (although the expected type would be Function0<number>
which is basicalyl the same).
@YuseiUeno One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you! |
This is Function Overloads Ordering Problem. |
@@ -655,7 +655,6 @@ declare module "../index" { | |||
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: __, plc2: __, arg3: T3): Function3<T1, T2, T4, R>; | |||
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, plc2: __, arg3: T3): Function2<T2, T4, R>; | |||
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, plc1: __, arg2: T2, arg3: T3): Function2<T1, T4, R>; | |||
<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, arg3: T3): Function1<T4, R>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah I missed the overload below which does this. Thanks!
@YuseiUeno: Everything looks good here. I am ready to merge this PR (at d293cb4) on your behalf whenever you think it's ready. If you'd like that to happen, please post a comment saying:
and I'll merge this PR almost instantly. Thanks for helping out! ❤️ (@bczengel, @chrootsu, @aj-r, @e-cloud, @thorn0, @jtmthf, @DomiR, @WilliamChelman: you can do this too.) |
Ready to merge |
Please fill in this template.
pnpm test <package to test>
.Select one of these and delete the others:
If changing an existing definition:
package.json
.https://www.typescriptlang.org/play/?ssl=13&ssc=9&pln=12&pc=1#code/JYWwDg9gTgLgBAfQDRwN5wGIFcB2BjGYCHFAGQgBEBDAZwAsBlGKwvOAXzgDMoIQ4A5ABsIAE1p0BAWABQsvMRrwuARjgBeOAAoqALjg4sIAEYBTKAEoNAPjhUA3PMXKATBu16DRs1BTH9SlDAOADmVuq2VHAA1HDGjjIKOErcAMzuOvqGJuZ+ATBBoSh4+sYQEEKmVDjhkTFx9XgJSSlcACwZntk+eXCBwSHFpeWV1SiiWd7mtXb1xo31oglOyfBgapoIAHRgVLDAVEIAPADaALoo3bleOVDWWqooKgAMFgkA9O9w33AAegD8KxSYDcmx2e0IhweLiezxQAioxjwAjesk+Pz+gMSzjgYHSYN2+yhXFSsPhiORKAKWFMqJk6J+AKBaw6BIhByEDzaZMEFIEVKgNNhdIZ3yZMiAA
p3
must be() => string
. But below.<T1, T2, T3, T4, R>(func: Function4<T1, T2, T3, T4, R>, arg1: T1, arg2: T2, arg3: T3): Function1<T4, R>;
brake<TS extends any[], T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3, ...ts: TS) => R, t1: T1, t2: T2, t3: T3): (...ts: TS) => R;
by overload