From 24f9ca39b816ff67d259753532ab3a8b9cb02ad4 Mon Sep 17 00:00:00 2001 From: haozi Date: Fri, 15 Mar 2024 14:50:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Type=20constraints=20pro?= =?UTF-8?q?hibit=20returning=20undefined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- plugins/browser-storage/src/index.ts | 4 +++- plugins/node-fs/src/index.ts | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 43ee583..f3d6396 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "idmp", - "version": "1.15.1", + "version": "1.15.2", "keywords": [ "deduplicate network requests", "idempotent function", diff --git a/plugins/browser-storage/src/index.ts b/plugins/browser-storage/src/index.ts index cbd1117..19cff5e 100644 --- a/plugins/browser-storage/src/index.ts +++ b/plugins/browser-storage/src/index.ts @@ -3,6 +3,8 @@ import { getOptions, type Idmp, type IdmpOptions, type IdmpPromise } from 'idmp' const udf = undefined type StorageType = 'localStorage' | 'sessionStorage' +type NonVoid = T extends void ? never : T + const getCacheKey = (globalKey: string) => `@idmp/v1/${globalKey}` const initStorage = (storageType: StorageType) => { @@ -66,7 +68,7 @@ const storageIdmpWrap = ( const storage = initStorage(storageType) const newIdmp = ( globalKey: string, - promiseFunc: IdmpPromise, + promiseFunc: IdmpPromise>, options?: IdmpOptions, ) => { const finalOptions = getOptions(options) diff --git a/plugins/node-fs/src/index.ts b/plugins/node-fs/src/index.ts index 7f76845..d30fa41 100644 --- a/plugins/node-fs/src/index.ts +++ b/plugins/node-fs/src/index.ts @@ -48,10 +48,12 @@ const getData = async (key: string) => { return data as T } +type NonVoid = T extends void ? never : T + const fsIdmpWrap = (_idmp: Idmp) => { const newIdmp = ( globalKey: string, - promiseFunc: IdmpPromise, + promiseFunc: IdmpPromise>, options?: IdmpOptions, ) => { const finalOptions = getOptions(options)