Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

apollo-link-http-common references type GlobalFetch, to be removed in Typescript 3.6 #1094

Closed
sandersn opened this issue Jun 19, 2019 · 3 comments · Fixed by #1095
Closed

Comments

@sandersn
Copy link
Contributor

Expected Behavior
No error when compiling Definitely Typed types for apollo-upload-client:

import { ApolloLink } from "apollo-link";
import { HttpOptions } from "apollo-link-http-common";
export { ReactNativeFile } from "extract-files";
export function createUploadLink(linkOptions?: HttpOptions): ApolloLink;

Actual Behavior
Error in apollo-link-http-common's types, which refer to GlobalFetch. GlobalFetch will be removed in Typescript 3.6 in favour of WindowOrWebWorker, which has the same fetch method:

export interface HttpOptions {
    // ........
    /**
     * A `fetch`-compatible API to use when making requests.
     */
    fetch?: GlobalFetch['fetch'];
    // .........
}

A simple reproduction

npm install -g typescript@next
cd packages/apollo-link-http-common/src
tsc

Gives the errors:

index.ts:74:11 - error TS2304: Cannot find name 'GlobalFetch'.

74   fetch?: GlobalFetch['fetch'];
             ~~~~~~~~~~~

index.ts:174:39 - error TS2304: Cannot find name 'GlobalFetch'.

174 export const checkFetcher = (fetcher: GlobalFetch['fetch']) => {

(This is not the right way to build this file, so there are 4 other errors. You will only see those 4 if you use typescript@latest)

The fix is to replace GlobalFetch with WindowOrWorkerGlobalScope. I'll put up a PR that does this shortly.

sandersn added a commit to sandersn/apollo-link that referenced this issue Jun 19, 2019
Fixes compilation of apollo-link-http-common in the upcoming Typescript
3.6.

Fixes apollographql#1094
benjamn pushed a commit that referenced this issue Jun 20, 2019
Fixes compilation of apollo-link-http-common in the upcoming Typescript 3.6.

Fixes #1094
@eturino
Copy link

eturino commented Sep 11, 2019

@sandersn @benjamn when installing apollo-boost on a node server, we still get this issue. The problem seems to be on the declaration file

node_modules/apollo-boost/lib/index.d.ts:25:13 - error TS2304: Cannot find name 'GlobalFetch'.

25     fetch?: GlobalFetch['fetch'];
               ~~~~~~~~~~~

maybe apollo-boost needs to be updated too?

@abdonrd
Copy link

abdonrd commented Sep 23, 2019

@eturino new PR about this: apollographql/apollo-client#5367

@shershen08
Copy link

I added to my src/shims-tsx.d.ts this to get rid of this warning

declare type GlobalFetch {
  fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
};```

bkegley added a commit to bkegley/apollo-client that referenced this issue Oct 29, 2019
Per this resolved [issue](apollographql/apollo-link#1094), apollo-boost should also remove reference to `GlobalFetch`.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants