Skip to content

Commit

Permalink
added fetch api type definitions extracted from official dom lib usin…
Browse files Browse the repository at this point in the history
…g ts-graft (#93)

lib.fetch.d.ts includes all types from the dom lib needed to define the
fetch function and the Request, Response, and Headers classes. The file
was generated by ts-graft as follows:

npm i --no-save typescript@4.2.3 \
&& cat <<EOF > .ts-graftrc.yaml \
&& npx ts-graft@1.0.1 \
&& rm .ts-graftrc.yaml \
&& npm un typescript
grafts:
- source: typescript/lib/lib.dom.d.ts
  output: lib.fetch.d.ts
  include: [RequestInfo, RequestInit, Response]
EOF
  • Loading branch information
jstewmon committed Mar 12, 2021
1 parent 1cd5110 commit a896ff3
Show file tree
Hide file tree
Showing 3 changed files with 463 additions and 10 deletions.
31 changes: 22 additions & 9 deletions index.d.ts
@@ -1,14 +1,27 @@
/// <reference lib="dom" />
import {
Headers,
Request,
RequestInfo,
RequestInit,
Response,
} from "./lib.fetch"

declare const _fetch: typeof fetch;
declare const _Request: typeof Request;
declare const _Response: typeof Response;
declare const _Headers: typeof Headers;

declare module "cross-fetch" {
export const fetch: typeof _fetch;
export const Request: typeof _Request;
export const Response: typeof _Response;
export const Headers: typeof _Headers;
export const fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
export const Request: {
prototype: Request;
new(input: RequestInfo, init?: RequestInit): Request;
};
export const Response: {
prototype: Response;
new(body?: BodyInit | null, init?: ResponseInit): Response;
error(): Response;
redirect(url: string, status?: number): Response;
};
export const Headers: {
prototype: Headers;
new(init?: HeadersInit): Headers;
};
export default fetch;
}

0 comments on commit a896ff3

Please sign in to comment.