Skip to content

Commit 3565fdd

Browse files
committed
add type truthy key
1 parent a6b97ab commit 3565fdd

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

_internal/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as revalidateEvents from './constants'
22
import { defaultConfig } from './utils/config'
33

4-
export type Falsy = undefined | null | false
4+
type Falsy = null | undefined | false
5+
export type TruthyKey = Exclude<Arguments, Falsy>
56

67
export type GlobalState = [
78
Record<string, RevalidateCallback[]>, // EVENT_REVALIDATORS
@@ -10,7 +11,7 @@ export type GlobalState = [
1011
ScopedMutator, // Mutator
1112
(key: string, value: any, prev: any) => void, // Setter
1213
(key: string, callback: (current: any, prev: any) => void) => () => void, // Subscriber
13-
Set<Omit<Arguments, 'null' | 'undefined'>> // Keys
14+
Set<TruthyKey> // Keys
1415
]
1516
export type FetcherResponse<Data = unknown> = Data | Promise<Data>
1617
export type BareFetcher<Data = unknown> = (

_internal/utils/mutate.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {
99
MutatorOptions,
1010
GlobalState,
1111
State,
12-
Arguments
12+
Arguments,
13+
TruthyKey
1314
} from '../types'
1415

15-
type ValidKey = Omit<Arguments, 'null' | 'undefined'>
16-
type KeyFilter = (key?: ValidKey) => boolean
16+
type KeyFilter = (key?: TruthyKey) => boolean
1717

1818
export async function internalMutate<Data>(
1919
cache: Cache,
@@ -66,7 +66,7 @@ export async function internalMutate<Data>(
6666
return await mutateByKey(serializedKey)
6767
}
6868

69-
async function mutateByKey(_k: ValidKey): Promise<Data | undefined> {
69+
async function mutateByKey(_k: TruthyKey): Promise<Data | undefined> {
7070
const [key] = serialize(_k)
7171
const [get, set] = createCacheHelper<
7272
Data,

0 commit comments

Comments
 (0)