From f3f0c25601c340d21a55aa4759115b2c06f728f9 Mon Sep 17 00:00:00 2001 From: Jonathan Stewmon Date: Wed, 10 Mar 2021 21:59:30 -0600 Subject: [PATCH] chore: use ts-graft to include requisite types from dom lib --- .gitignore | 1 + .ts-graftrc.js | 9 +++++++++ Makefile | 2 +- index.d.ts | 31 ++++++++++++++++++++++--------- package.json | 3 +++ 5 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 .ts-graftrc.js diff --git a/.gitignore b/.gitignore index bd2263a..1e238f8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.log test.ponyfill.js test.polyfill.js +dom.d.ts # OSX # diff --git a/.ts-graftrc.js b/.ts-graftrc.js new file mode 100644 index 0000000..fc94d4f --- /dev/null +++ b/.ts-graftrc.js @@ -0,0 +1,9 @@ +module.exports = { + grafts: [ + { + source: "typescript/lib/lib.dom.d.ts", + output: "dom.d.ts", + include: ["RequestInit", "RequestInfo", "Response"], + }, + ], +}; diff --git a/Makefile b/Makefile index d268de5..73a99b9 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ node_modules: package.json npm install && /usr/bin/touch node_modules build: node_modules - npx rollup -c && /usr/bin/touch dist + npx ts-graft && npx rollup -c && /usr/bin/touch dist cov: npx nyc report --reporter=text-lcov > .reports/coverage.lcov && npx codecov diff --git a/index.d.ts b/index.d.ts index 3c030c0..961a444 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,14 +1,27 @@ -/// +import { + Request, + Response, + Headers, + RequestInfo, + RequestInit +} from "./dom" -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; + 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; } diff --git a/package.json b/package.json index c2e33da..7462254 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,8 @@ "serve-index": "1.9.1", "sinon": "9.2.4", "standard": "16.0.3", + "ts-graft": "1.0.1", + "typescript": "4.2.3", "webpack": "5.19.0", "webpack-cli": "4.4.0", "whatwg-fetch": "3.0.0" @@ -84,6 +86,7 @@ "files": [ "dist", "polyfill", + "dom.d.ts", "index.d.ts" ], "keywords": [