From b4c8971788c70b09479946ecfa998cff2f1b3953 Mon Sep 17 00:00:00 2001 From: Tom Meagher Date: Thu, 8 Aug 2024 20:47:37 -0400 Subject: [PATCH] fix: #4196 --- .changeset/big-humans-sleep.md | 5 +++++ packages/core/src/createStorage.test-d.ts | 12 ++++++++++++ packages/core/src/createStorage.ts | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 .changeset/big-humans-sleep.md diff --git a/.changeset/big-humans-sleep.md b/.changeset/big-humans-sleep.md new file mode 100644 index 0000000000..d06c87ad38 --- /dev/null +++ b/.changeset/big-humans-sleep.md @@ -0,0 +1,5 @@ +--- +"@wagmi/core": patch +--- + +Made `serialize` and `deserialize` types more permissive. diff --git a/packages/core/src/createStorage.test-d.ts b/packages/core/src/createStorage.test-d.ts index 0761cccda9..6bb4c7f300 100644 --- a/packages/core/src/createStorage.test-d.ts +++ b/packages/core/src/createStorage.test-d.ts @@ -60,3 +60,15 @@ test('setItem', () => { // @ts-expect-error incorrect argument type storage.setItem('recentConnectorId', 1n) }) + +test('serialize/deserialize types', () => { + createStorage({ + deserialize(value) { + return value + }, + serialize(value) { + return value + }, + storage: localStorage, + }) +}) diff --git a/packages/core/src/createStorage.ts b/packages/core/src/createStorage.ts index 5667e8ee89..06854c0b55 100644 --- a/packages/core/src/createStorage.ts +++ b/packages/core/src/createStorage.ts @@ -41,9 +41,9 @@ export type BaseStorage = { } export type CreateStorageParameters = { - deserialize?: ((value: string) => T) | undefined + deserialize?: ((value: string) => type | unknown) | undefined key?: string | undefined - serialize?: ((value: T) => string) | undefined + serialize?: ((value: type | any) => string) | undefined storage?: Compute | undefined }