-
-
Notifications
You must be signed in to change notification settings - Fork 852
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
TS Error: finishDraft Expected 2 arguments, but got 1. #492
Labels
Comments
This is definitely not intended indeed. Feel free to // @ts-ignore until
fixed
Op ma 23 dec. 2019 11:30 schreef Eddy Wilson <[email protected]>:
… 🐛 Bug Report
TS complains that the second argument for finishDraft is required.
To Reproduce
const final = finishDraft(draft)
Observed behavior
Our build started to fail with latest version of immer:
TS2554: Expected 2 arguments, but got 1.
96 const cssAttributesFinal = finishDraft(cssAttributes)
~~~~~~~
And it's everywhere. There is no update in the docs that the patch
listener has become a required argument, so I think this is a bug with
typings of the function.
Expected behavior
The second argument for finishDraft should be optional.
Environment
- *Immer version: 5.0.1*
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#492?email_source=notifications&email_token=AAN4NBCVYEKE4LNFTXTGOMDQ2CHNZA5CNFSM4J6SQMTKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICJRJHQ>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBHPMVLL65NXAMUF2DTQ2CHNZANCNFSM4J6SQMTA>
.
|
To save anyone who investigates this some time, the following is not a valid fix. You would think this would work, however after applying this patch, diff --git i/src/immer.ts w/src/immer.ts
index a6d94cf..6457493 100644
--- i/src/immer.ts
+++ w/src/immer.ts
@@ -178,7 +178,7 @@ export class Immer implements ProducersFns {
return proxy as any
}
- finishDraft<D extends Draft<any>>(draft: D, patchListener: PatchListener): D extends Draft<infer T> ? T : never {
+ finishDraft<D extends Draft<any>>(draft: D, patchListener?: PatchListener): D extends Draft<infer T> ? T : never {
const state = draft && draft[DRAFT_STATE]
if (!state || !state.isManual) {
throw new Error("First argument to `finishDraft` must be a draft returned by `createDraft`") // prettier-ignore
diff --git i/src/scope.ts w/src/scope.ts
index 4436fea..72d185f 100644
--- i/src/scope.ts
+++ w/src/scope.ts
@@ -24,7 +24,7 @@ export class ImmerScope {
this.patches = null as any // TODO:
}
- usePatches(patchListener: PatchListener) {
+ usePatches(patchListener?: PatchListener) {
if (patchListener) {
this.patches = []
this.inversePatches = [] This results in an
|
mweststrate
added a commit
that referenced
this issue
Jan 9, 2020
mweststrate
added a commit
that referenced
this issue
Jan 9, 2020
🎉 This issue has been resolved in version 5.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🐛 Bug Report
TS complains that the second argument for
finishDraft
is required.To Reproduce
Observed behavior
Our build started to fail with latest version of immer:
And it's everywhere. There is no update in the docs that the patch listener has become a required argument, so I think this is a bug with typings of the function.
Expected behavior
The second argument for
finishDraft
should be optional.Environment
The text was updated successfully, but these errors were encountered: