From 8777e24ff36a00a6faaff4fc21ef6af52bf79814 Mon Sep 17 00:00:00 2001 From: Olavi Mustanoja Date: Thu, 15 Feb 2018 13:54:17 +0200 Subject: [PATCH 1/4] fix ts declarations to support currying and immutable state --- src/immer.d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/immer.d.ts b/src/immer.d.ts index 17aec72f..c8ee853b 100644 --- a/src/immer.d.ts +++ b/src/immer.d.ts @@ -1,3 +1,7 @@ +type Mutable = { + [P in K]: T[P]; +} + /** * Immer takes a state, and runs a function against it. * That function can freely mutate the state, as it will create copies-on-write. @@ -12,7 +16,7 @@ */ export default function( currentState: S, - recipe: (this: S, draftState: S) => void + recipe?: (this: S, draftState: Mutable) => void ): S // curried invocations export default function( From 862acf6d927ff7b63dc772c7176555b5baef490c Mon Sep 17 00:00:00 2001 From: Olavi Mustanoja Date: Thu, 15 Feb 2018 14:34:06 +0200 Subject: [PATCH 2/4] export MutableState and Recipe types --- src/immer.d.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/immer.d.ts b/src/immer.d.ts index c8ee853b..5adfd209 100644 --- a/src/immer.d.ts +++ b/src/immer.d.ts @@ -1,7 +1,9 @@ -type Mutable = { +export type MutableState = { [P in K]: T[P]; } +export type Recipe = (this: S, draftState: MutableState) => void; + /** * Immer takes a state, and runs a function against it. * That function can freely mutate the state, as it will create copies-on-write. @@ -11,12 +13,12 @@ type Mutable = { * any time it is called with a base state * * @param currentState - the state to start with - * @param thunk - function that receives a proxy of the current state as first argument and which can be freely modified + * @param recipe - function that receives a proxy of the current state as first argument and which can be freely modified * @returns The next state: a new state, or the current state if nothing was modified */ export default function( currentState: S, - recipe?: (this: S, draftState: Mutable) => void + recipe?: Recipe ): S // curried invocations export default function( From 3228d96a0b9500e26f35ad3fed277b28fba7b84e Mon Sep 17 00:00:00 2001 From: Olavi Mustanoja Date: Thu, 15 Feb 2018 14:36:18 +0200 Subject: [PATCH 3/4] use spaces instead of tabs --- src/immer.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/immer.d.ts b/src/immer.d.ts index 5adfd209..c6fa1920 100644 --- a/src/immer.d.ts +++ b/src/immer.d.ts @@ -1,5 +1,5 @@ export type MutableState = { - [P in K]: T[P]; + [P in K]: T[P]; } export type Recipe = (this: S, draftState: MutableState) => void; From a01a0ff9e57d31251816cce4a4fac9d3af2e7c46 Mon Sep 17 00:00:00 2001 From: Olavi Mustanoja Date: Wed, 21 Feb 2018 02:24:24 +0200 Subject: [PATCH 4/4] make draftState mutable recursively --- src/immer.d.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/immer.d.ts b/src/immer.d.ts index c6fa1920..e2df956f 100644 --- a/src/immer.d.ts +++ b/src/immer.d.ts @@ -1,8 +1,4 @@ -export type MutableState = { - [P in K]: T[P]; -} - -export type Recipe = (this: S, draftState: MutableState) => void; +export type Recipe = (this: S, draftState: S | any) => void; /** * Immer takes a state, and runs a function against it.