Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions _internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,22 @@ export type SWRConfiguration<
Fn extends BareFetcher<any> = BareFetcher<any>
> = Partial<PublicConfiguration<Data, Error, Fn>>

export interface SWRResponse<Data = any, Error = any> {
data: Data | undefined
error: Error | undefined
mutate: KeyedMutator<Data>
export type SWRResponse<Data = any, Error = any> = { mutate: KeyedMutator<Data> } & ({
data: undefined
error: undefined
isValidating: true
isLoading: true
} | {
data: Data
error: undefined
isValidating: boolean
isLoading: boolean
}
isLoading: false
} | {
data: undefined
error: Error
isValidating: boolean
isLoading: false
})

export type KeyLoader<Args extends Arguments = Arguments> =
| ((index: number, previousPageData: any | null) => Args)
Expand Down
3 changes: 1 addition & 2 deletions infinite/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export interface SWRInfiniteConfiguration<
fetcher?: Fn
}

export interface SWRInfiniteResponse<Data = any, Error = any>
extends SWRResponse<Data[], Error> {
export type SWRInfiniteResponse<Data = any, Error = any> = SWRResponse<Data[], Error> & {
size: number
setSize: (
size: number | ((_size: number) => number)
Expand Down