From 96941048e4633404967a185ff06ab67b3fc728b0 Mon Sep 17 00:00:00 2001 From: Daniele Morosinotto Date: Mon, 26 Mar 2018 03:29:08 +0200 Subject: [PATCH] Update immer.d.ts to correctly type check the use-case of producers that return new state --- src/immer.d.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/immer.d.ts b/src/immer.d.ts index 6e80a582..e5e58390 100644 --- a/src/immer.d.ts +++ b/src/immer.d.ts @@ -13,60 +13,60 @@ */ export default function( currentState: S, - recipe: (this: S, draftState: S) => void + recipe: (this: S, draftState: S) => void | S ): S // curried invocations with default initial state // 0 additional arguments export default function( - recipe: (this: S, draftState: S) => void, + recipe: (this: S, draftState: S) => void | S, initialState: S ): (currentState: S | undefined) => S // 1 additional argument of type A export default function( - recipe: (this: S, draftState: S, a: A) => void, + recipe: (this: S, draftState: S, a: A) => void | S, initialState: S ): (currentState: S | undefined, a: A) => S // 2 additional arguments of types A and B export default function( - recipe: (this: S, draftState: S, a: A, b: B) => void, + recipe: (this: S, draftState: S, a: A, b: B) => void | S, initialState: S ): (currentState: S | undefined, a: A, b: B) => S // 3 additional arguments of types A, B and C export default function( - recipe: (this: S, draftState: S, a: A, b: B, c: C) => void, + recipe: (this: S, draftState: S, a: A, b: B, c: C) => void | S, initialState: S ): (currentState: S | undefined, a: A, b: B, c: C) => S // any number of additional arguments, but with loss of type safety // this may be alleviated if "variadic kinds" makes it into Typescript: // https://github.com/Microsoft/TypeScript/issues/5453 export default function( - recipe: (this: S, draftState: S, ...extraArgs: any[]) => void, + recipe: (this: S, draftState: S, ...extraArgs: any[]) => void | S, initialState: S ): (currentState: S | undefined, ...extraArgs: any[]) => S // curried invocations without default initial state // 0 additional arguments export default function( - recipe: (this: S, draftState: S) => void + recipe: (this: S, draftState: S) => void | S ): (currentState: S) => S // 1 additional argument of type A export default function( - recipe: (this: S, draftState: S, a: A) => void + recipe: (this: S, draftState: S, a: A) => void | S ): (currentState: S, a: A) => S // 2 additional arguments of types A and B export default function( - recipe: (this: S, draftState: S, a: A, b: B) => void + recipe: (this: S, draftState: S, a: A, b: B) => void | S ): (currentState: S, a: A, b: B) => S // 3 additional arguments of types A, B and C export default function( - recipe: (this: S, draftState: S, a: A, b: B, c: C) => void + recipe: (this: S, draftState: S, a: A, b: B, c: C) => void | S ): (currentState: S, a: A, b: B, c: C) => S // any number of additional arguments, but with loss of type safety // this may be alleviated if "variadic kinds" makes it into Typescript: // https://github.com/Microsoft/TypeScript/issues/5453 export default function( - recipe: (this: S, draftState: S, ...extraArgs: any[]) => void + recipe: (this: S, draftState: S, ...extraArgs: any[]) => void | S ): (currentState: S, ...extraArgs: any[]) => S /** * Automatically freezes any state trees generated by immer.