Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert swr config generic #2065

Merged
merged 2 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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))
}
10 changes: 2 additions & 8 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 { Cache } 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)
expectType<Cache<any>>(useSWRConfig().cache)
}

export function useCustomSWRConfig() {
Expand Down