Skip to content

Commit

Permalink
nit(ts): change nothing to a unique symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jan 21, 2019
1 parent 883a258 commit 923f6c3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/immer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ export interface Patch {

export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void

/** Used for `void` and `undefined` detection */
type IsVoidLike<T> = T extends void | undefined ? 1 : 0

/** Converts `nothing` into `undefined` */
type FromNothing<T> = Nothing extends T ? Exclude<T, Nothing> | undefined : T
type FromNothing<T> = typeof nothing extends T
? Exclude<T, typeof nothing> | undefined
: T

/** The inferred return type of `produce` */
export type Produced<T, Return> = IsVoidLike<Return> extends 0
Expand Down Expand Up @@ -111,16 +114,10 @@ export interface IProduce {
export const produce: IProduce
export default produce

/** Use a class type for `nothing` so its type is unique */
declare class Nothing {
// This lets us do `Exclude<T, Nothing>`
private _: any
}

/**
* The sentinel value returned by producers to replace the draft with undefined.
*/
export const nothing: Nothing
export const nothing: unique symbol

/**
* Pass true to automatically freeze all copies created by Immer.
Expand Down

0 comments on commit 923f6c3

Please sign in to comment.