apollo-client: RequestInit is not defined in typescript typings

Thanks for this amazing project! Loving it! A small detail:

When using apollo-client in typescript the RequestInit is not defined. It also references the graphql library which typings is not a part of the project.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 26 (12 by maintainers)

Most upvoted comments

Why close this, I’m facing this problem and I don’t want to include dom lib to my server project

Here is my solution:

"lib": [
	"dom",
	"es2017",
	"esnext.asynciterable"
]

Closing this, since it’s quite dated and seems to have been solved.

RequestInit is defined in fetch (isomorphic-fetch):

interface RequestInit {
    method?: string;
    headers?: HeaderInit | { [index: string]: string };
    body?: BodyInit;
    mode?: string | RequestMode;
    credentials?: string | RequestCredentials;
    cache?: string | RequestCache;
}

@patriknil90 You should install isomorphic-fetch as one of npm dependencies to add the polyfill.

Then install typings as follows:

To resolve missing RequestInit and IResponse you should run:

typings i -SG dt~isomorphic-fetch // or use @types/isomorphic-fetch from npm

To fill the gap with NodeJS:

typings i -SG env~node // or use @types/node from npm

@stubailo I noticed that IResponse is specific to isomorphic-fetch, typings of whatwg-fetch doesn’t include it.

It all depends on the ambient declaration:

// file_a.d.ts
declare interface Foo { }

// file_b.d.ts

declare module "graphql" {
   export interface Bar { }
}

Foo is accessible globaly Bar you have to import from “graphql”