Skip to content
Myr

fix: createDraft should return `Draft` instead of `Drafted`. Fixes #512

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michel Weststrate · committed by Michel Weststrate · parent ef8990b · Browse files · 2 files+7 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−2 removed

  • tests:+5 added−0 removed
  • other:+2 added−2 removed

2 files+7 added−2 removed

modified:__tests__/draft.ts+5 added
328 unmodified lines
329test("asDraft preserves a value", () => {330 const x = {}331 expect(castDraft(x)).toBe(x)332})333334test("#512 createDraft creates a draft", () => {335 const x = {y: 1}336 assert(x, _ as Draft<{y: number}>)337})
modified:src/immer.ts+2 added-2 removed
175 unmodified lines
176 })177 return [nextState, patches!, inversePatches!]178 }179180 createDraft<T extends Objectish>(base: T): Drafted<T> {180 createDraft<T extends Objectish>(base: T): Draft<T> {181 if (!isDraftable(base)) {182 throw new Error("First argument to `createDraft` must be a plain object, an array, or an immerable object") // prettier-ignore183 }184 const scope = ImmerScope.enter(this)185 const proxy = this.createProxy(base, undefined)186 proxy[DRAFT_STATE].isManual = true187 scope.leave()188 return proxy188 return proxy as any189 }190191 finishDraft<D extends Draft<any>>(192 draft: D,
85 unmodified lines