Skip to content

Commit

Permalink
feat: 🎸 Type constraints prohibit returning undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
haozi committed Mar 15, 2024
1 parent a038f59 commit 24f9ca3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "idmp",
"version": "1.15.1",
"version": "1.15.2",
"keywords": [
"deduplicate network requests",
"idempotent function",
Expand Down
4 changes: 3 additions & 1 deletion plugins/browser-storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { getOptions, type Idmp, type IdmpOptions, type IdmpPromise } from 'idmp'
const udf = undefined

type StorageType = 'localStorage' | 'sessionStorage'
type NonVoid<T> = T extends void ? never : T

const getCacheKey = (globalKey: string) => `@idmp/v1/${globalKey}`

const initStorage = (storageType: StorageType) => {
Expand Down Expand Up @@ -66,7 +68,7 @@ const storageIdmpWrap = (
const storage = initStorage(storageType)
const newIdmp = <T>(
globalKey: string,
promiseFunc: IdmpPromise<T>,
promiseFunc: IdmpPromise<NonVoid<T>>,
options?: IdmpOptions,
) => {
const finalOptions = getOptions(options)
Expand Down
4 changes: 3 additions & 1 deletion plugins/node-fs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ const getData = async <T = any>(key: string) => {
return data as T
}

type NonVoid<T> = T extends void ? never : T

const fsIdmpWrap = (_idmp: Idmp) => {
const newIdmp = <T>(
globalKey: string,
promiseFunc: IdmpPromise<T>,
promiseFunc: IdmpPromise<NonVoid<T>>,
options?: IdmpOptions,
) => {
const finalOptions = getOptions(options)
Expand Down

0 comments on commit 24f9ca3

Please sign in to comment.