Skip to content

Commit

Permalink
fix: fix mergeConfigs function typing
Browse files Browse the repository at this point in the history
  • Loading branch information
edumudu committed Jul 16, 2022
1 parent a32c921 commit 620c089
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/composables/swr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const useSWR = <Data = any, Error = any>(
const fetchedIn = hasCachedValue.value ? toRef(valueInCache.value, 'fetchedIn') : ref(new Date());

const fetchData = async () => {
const timestampToDedupExpire = (fetchedIn.value?.getTime() || 0) + (dedupingInterval || 0);
const timestampToDedupExpire = (fetchedIn.value?.getTime() || 0) + dedupingInterval;

if (hasCachedValue.value && timestampToDedupExpire > Date.now()) return;

Expand Down
6 changes: 3 additions & 3 deletions lib/utils/merge-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SWRConfig } from '@/types';

export const mergeConfig = (
fallbackConfig: Partial<SWRConfig>,
config: Partial<SWRConfig> = {},
export const mergeConfig = <T extends Partial<SWRConfig>, D extends Partial<SWRConfig>>(
fallbackConfig: T,
config: D,
) => ({
...fallbackConfig,
...config,
Expand Down
2 changes: 0 additions & 2 deletions lib/utils/merge-config/merge-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { mergeConfig } from '.';

describe('mergeConfig', () => {
it.each([
[{}, {}, {}],
[{}, undefined, {}],
[{}, { revalidateIfStale: true }, { revalidateIfStale: true }],
[{ revalidateIfStale: true }, {}, { revalidateIfStale: true }],
[{ revalidateIfStale: true }, { revalidateIfStale: true }, { revalidateIfStale: true }],
Expand Down

0 comments on commit 620c089

Please sign in to comment.