Skip to content

Commit

Permalink
fix: Add missing type current for pre-TS 3.7 types
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jun 12, 2020
2 parents 467ea5d + 04f8b52 commit 7d6b57b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compat/pre-3.7/dist/immer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ export function finishDraft<T>(draft: T, listener?: PatchListener): Immutable<T>
/** Get the underlying object that is represented by the given draft */
export function original<T>(value: T): T | void

/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */
export function current<T>(value: T): T

/** Returns true if the given value is an Immer draft */
export function isDraft(value: any): boolean

Expand Down
2 changes: 1 addition & 1 deletion docs/current.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Objects generated by `current` work similar to the objects created by produce it
1. Unmodified objects will be structurally shared with the original objects.
1. If no changes are made to a draft, generally it holds that `original(draft) === current(draft)`, but this is not guaranteed.
1. Future changes to the draft won't be reflected in the object produced by `current` (except for references to undraftable objects)
1. Unlinke `produce` objects created by `current` will _not_ be frozen.
1. Unlike `produce` objects created by `current` will _not_ be frozen.

Use `current` sparingly, it can be a potentially expensive operation, especially when using ES5.

Expand Down
1 change: 1 addition & 0 deletions src/core/current.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getPlugin
} from "../internal"

/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */
export function current<T>(value: T): T
export function current(value: any): any {
if (!isDraft(value)) die(22, value)
Expand Down

0 comments on commit 7d6b57b

Please sign in to comment.