Skip to content
Myr

fix: update current and original typings to assert draft value is unwrapped (#1236)

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

authored by Dean Kerr · committed by GitHub · parent 7390d6c · Browse files · 4 files+32 added−6 removed
This commit

State

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

Diff stats

4 files+32 added−6 removed

  • tests:+25 added−0 removed
  • other:+7 added−6 removed

4 files+32 added−6 removed

modified:__tests__/type-external.ts+25 added
modified:src/core/current.ts+3 added-2 removed
modified:src/core/immerClass.ts+1 added-1 removed
149 unmodified lines
150 }151152 createDraft<T extends Objectish>(base: T): Draft<T> {153 if (!isDraftable(base)) die(8)154 if (isDraft(base)) base = current(base)154 if (isDraft(base)) base = current(base as Draft<T>)155 const scope = enterScope(this)156 const proxy = createProxy(scope, base, undefined)157 proxy[DRAFT_STATE].isManual_ = true158 leaveScope(scope)
115 unmodified lines
modified:src/utils/common.ts+3 added-3 removed
1import {2 DRAFT_STATE,3 DRAFTABLE,4 Objectish,5 Drafted,5 Draft,6 AnyObject,7 AnyMap,8 AnySet,9 ImmerState,
55 unmodified lines
65}6667/** Get the underlying object that is represented by the given draft */68/*#__PURE__*/69export function original<T>(value: T): T | undefined70export function original(value: Drafted<any>): any {69export function original<T>(value: Draft<T>): T70export function original(value: Draft<any>): any {71 if (!isDraft(value)) die(15, value)72 return value[DRAFT_STATE].base_73}74
212 unmodified lines