Skip to content

Commit

Permalink
feat: inline TypeScript fetch types
Browse files Browse the repository at this point in the history
closes #15
closes #26
Relates to #100
Relates to #108

This approach was originally implemented by @kallaspriit in #100.

This approach ships TypeScript types inline with this library rather
than relying on global fetch types in lib.dom.d.ts.

The benefits of this approach are:

1. It avoids consumers (direct or indirect) needing to add `dom` to
   their lib setting in tsconfig. This can be very confusing for Node
   projects and adds legitimate room for error since it allows any DOM
   globals to be used in the Node app which is almost certainly wrong.
2. The file-directive approach (see #108) fails in two ways:
    1. If consumers customize lib config but leave out `dom` things
       break just the same.
    2. It adds dom globals which is bad but now in a very
       unexpected/hidden way.
3. It aligns well with our ponyfill (not polyfill) approach.

The downsides of this approach are:

1. We aren't benefiting from improvements in the TS lib types. So
   improvements to fetch typing for example would not pass through to
   graphql-request users transparently. It would require a new release
   of graphql-request.
  • Loading branch information
jasonkuhrt committed May 29, 2020
1 parent ccaa5a1 commit cf90a8e
Show file tree
Hide file tree
Showing 2 changed files with 404 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference lib="dom" />

import fetch from 'cross-fetch'
import { ClientError, GraphQLError, Variables } from './types'
import { Request, RequestInit, Response } from './types.dom'

export { ClientError } from './types'

Expand Down
Loading

0 comments on commit cf90a8e

Please sign in to comment.