Skip to content

Commit

Permalink
Revert swr config generic
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jul 7, 2022
1 parent 48c04c2 commit 08dc1c9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
7 changes: 3 additions & 4 deletions _internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export type Fetcher<
: never

// Configuration types that are only used internally, not exposed to the user.
export interface InternalConfiguration<T extends Cache = Cache> {
cache: T
export interface InternalConfiguration {
cache: Cache
mutate: ScopedMutator
}

Expand Down Expand Up @@ -86,8 +86,7 @@ export interface PublicConfiguration<
isVisible: () => boolean
}

export type FullConfiguration<T extends Cache = Cache> =
InternalConfiguration<T> & PublicConfiguration
export type FullConfiguration = InternalConfiguration & PublicConfiguration

export type ProviderConfiguration = {
initFocus: (callback: () => void) => (() => void) | void
Expand Down
6 changes: 2 additions & 4 deletions _internal/utils/use-swr-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { useContext } from 'react'
import { defaultConfig } from './config'
import { SWRConfigContext } from './config-context'
import { mergeObjects } from './helper'
import type { FullConfiguration, Cache, State } from '../types'
import type { FullConfiguration } from '../types'

export const useSWRConfig = <
T extends Cache = Map<string, State>
>(): FullConfiguration<T> => {
export const useSWRConfig = (): FullConfiguration => {
return mergeObjects(defaultConfig, useContext(SWRConfigContext))
}
8 changes: 1 addition & 7 deletions test/type/config.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import React from 'react'
import type { Cache, State } from 'swr'
import type { State } from 'swr'
import { useSWRConfig, SWRConfig } from 'swr'
import { expectType } from './utils'

interface CustomCache<Data = any> extends Cache<Data> {
reset(): void
}

export function useTestCache() {
expectType<Map<string, State>>(useSWRConfig().cache)
expectType<Map<string, State>>(useSWRConfig<Map<string, State>>().cache)
expectType<CustomCache>(useSWRConfig<CustomCache>().cache)
}

export function useCustomSWRConfig() {
Expand Down

0 comments on commit 08dc1c9

Please sign in to comment.