Skip to content

Commit

Permalink
chore: use ts-graft to include requisite types from dom lib
Browse files Browse the repository at this point in the history
  • Loading branch information
jstewmon committed Mar 11, 2021
1 parent 019a2eb commit f3f0c25
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
*.log
test.ponyfill.js
test.polyfill.js
dom.d.ts

# OSX
#
Expand Down
9 changes: 9 additions & 0 deletions .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"],
},
],
};
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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
Expand Down
31 changes: 22 additions & 9 deletions index.d.ts
@@ -1,14 +1,27 @@
/// <reference lib="dom" />
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<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;
}
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -77,13 +77,16 @@
"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"
},
"files": [
"dist",
"polyfill",
"dom.d.ts",
"index.d.ts"
],
"keywords": [
Expand Down

0 comments on commit f3f0c25

Please sign in to comment.