Skip to content

Commit

Permalink
fix: createDraft should return Draft instead of Drafted. Fixes #512
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jan 16, 2020
1 parent ef8990b commit 3f15d49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions __tests__/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,8 @@ test("asDraft preserves a value", () => {
const x = {}
expect(castDraft(x)).toBe(x)
})

test("#512 createDraft creates a draft", () => {
const x = {y: 1}
assert(x, _ as Draft<{y: number}>)
})
4 changes: 2 additions & 2 deletions src/immer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ export class Immer implements ProducersFns {
return [nextState, patches!, inversePatches!]
}

createDraft<T extends Objectish>(base: T): Drafted<T> {
createDraft<T extends Objectish>(base: T): Draft<T> {
if (!isDraftable(base)) {
throw new Error("First argument to `createDraft` must be a plain object, an array, or an immerable object") // prettier-ignore
}
const scope = ImmerScope.enter(this)
const proxy = this.createProxy(base, undefined)
proxy[DRAFT_STATE].isManual = true
scope.leave()
return proxy
return proxy as any
}

finishDraft<D extends Draft<any>>(
Expand Down

0 comments on commit 3f15d49

Please sign in to comment.