mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-06 18:20:09 +00:00
Merge pull request #33567 from jonathanly/react-request
[react-request] add more types
This commit is contained in:
64
types/react-request/index.d.ts
vendored
64
types/react-request/index.d.ts
vendored
@@ -1,51 +1,73 @@
|
||||
// Type definitions for react-request 3.1
|
||||
// Project: https://github.com/jamesplease/react-request
|
||||
// Definitions by: Danny Cochran <https://github.com/dannycochran>
|
||||
// Angus Fretwell <https://github.com/angusfretwell>
|
||||
// Jonathan Ly <https://github.com/jonathanly>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.9
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
export interface RenderProps<T> {
|
||||
requestName: string;
|
||||
requestKey: string;
|
||||
fetching: boolean;
|
||||
failed: boolean;
|
||||
error: Error | null;
|
||||
response: Response | null;
|
||||
url: string;
|
||||
data: T | null;
|
||||
doFetch: (options?: FetchRequestProps) => Promise<void>;
|
||||
export interface FetchResponse<T> {
|
||||
url: string;
|
||||
init: any;
|
||||
failed: boolean;
|
||||
requestKey: string;
|
||||
response: Response | null;
|
||||
data: T | null;
|
||||
error: Error | null;
|
||||
didUnmount: boolean;
|
||||
}
|
||||
|
||||
export interface RenderProps<T> extends FetchResponse<T> {
|
||||
requestName: string;
|
||||
fetching: boolean;
|
||||
doFetch: DoFetch<T>;
|
||||
}
|
||||
|
||||
export interface FetchRequestProps extends RequestInit {
|
||||
lazy?: boolean;
|
||||
url: string;
|
||||
lazy?: boolean;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface FetchProps<T = any> extends FetchRequestProps {
|
||||
children?: (renderProps: RenderProps<T>) => React.ReactNode;
|
||||
afterFetch?: (args: FetchResponse<T>) => void;
|
||||
transformData?: (data: any) => T;
|
||||
children?: (renderProps: RenderProps<T>) => React.ReactNode;
|
||||
}
|
||||
|
||||
export interface DoFetchOptions extends RequestInit {
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export type DoFetch<T = any> = (
|
||||
options?: DoFetchOptions
|
||||
) => Promise<FetchResponse<T>>;
|
||||
|
||||
// TODO(dannycochran) RequestKeyOptions, ProxyRequest, fetchDedupe, getRequestKey, isRequestInFlight, clearRequestCache
|
||||
// should all be defined in an adjacent typings directory for fetch-dedupe.
|
||||
export interface RequestKeyOptions {
|
||||
url?: string;
|
||||
method?: string;
|
||||
responseType?: string;
|
||||
body?: string;
|
||||
url?: string;
|
||||
method?: string;
|
||||
responseType?: string;
|
||||
body?: string;
|
||||
}
|
||||
|
||||
export interface ProxyRequest {
|
||||
requestKey: string;
|
||||
res: Response;
|
||||
requestKey: string;
|
||||
res: Response;
|
||||
}
|
||||
|
||||
// TODO(dannycochran) Fill out fetchDedupe options.
|
||||
export function fetchDedupe(input: any, init?: any, dedupeOptions?: any): Promise<ProxyRequest>;
|
||||
export function fetchDedupe(
|
||||
input: any,
|
||||
init?: any,
|
||||
dedupeOptions?: any
|
||||
): Promise<ProxyRequest>;
|
||||
|
||||
export function getRequestKey(keyOptions?: RequestKeyOptions): string;
|
||||
export function isRequestInFlight(): boolean;
|
||||
export function clearRequestCache(): void;
|
||||
export function clearResponseCache(): void;
|
||||
|
||||
export class Fetch<T = any> extends React.Component<FetchProps<T>> { }
|
||||
export class Fetch<T = any> extends React.Component<FetchProps<T>> {}
|
||||
|
||||
Reference in New Issue
Block a user