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 @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?
@eturino new PR about this: https://github.com/apollographql/apollo-client/pull/5367
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>;
};
Most helpful comment
@sandersn @benjamn when installing apollo-boost on a node server, we still get this issue. The problem seems to be on the declaration file
maybe apollo-boost needs to be updated too?