Skip to content
Myr

fix(ts): produce() return type

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

The return type of `produce()` was not properly inferred when the producer returned anything other than undefined.

authored by aleclarson · committed by aleclarson · parent 06c8f6f · Browse files · 1 file+6 added−13 removed
This commit

State

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

Diff stats

1 file+6 added−13 removed

  • other:+6 added−13 removed

1 file+6 added−13 removed

modified:src/immer.d.ts+6 added-13 removed
41 unmodified lines
42}4344export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void4546/** Includes 1 when `void` or `undefined` exists in type `T` */47type HasVoidLike<T> = (void extends T ? 1 : 0) | (undefined extends T ? 1 : 0)46type IsVoidLike<T> = T extends void | undefined ? 1 : 04749/** Includes 1 when type `T` is `void` or `undefined` (or both) */50type IsVoidLike<T> =51 | (T extends void ? 1 : 0)52 | (T extends undefined ? 1 : 0)53 | (T extends void | undefined ? 1 : 0)5448/** Converts `nothing` into `undefined` */49type FromNothing<T> = Nothing extends T ? Exclude<T, Nothing> | undefined : T5051/** The inferred return type of `produce` */59type Produced<T, Return> = 1 extends HasVoidLike<Return>60 ? 1 extends IsVoidLike<Return>61 ? T62 : T | FromNothing<Exclude<Return, void>>63 : FromNothing<Return>52export type Produced<T, Return> = IsVoidLike<Return> extends 053 ? FromNothing<Return>54 : IsVoidLike<Return> extends 155 ? T56 : T | FromNothing<Exclude<Return, void>>5758type ImmutableTuple<T extends ReadonlyArray<any>> = {59 readonly [P in keyof T]: Immutable<T[P]>60}
147 unmodified lines