graphql-request: Close to working with TypeScript, but not quite -- Error: "Cannot find name RequestInit"
graphql-request doesn’t work with TypeScript projects. I’m seeing the following error:
node_modules/graphql-request/dist/src/types.d.ts(5,14): error TS2304: Cannot find name 'RequestInit'
I found the following related issue: RequestInit is not defined
Any help getting graphql-request working in TypeScript would be appreciated.
Thank you.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 31
- Comments: 25 (8 by maintainers)
Commits related to this issue
- feat: remove dom dependency (#108) Co-authored-by: Jason Kuhrt <jason.kuhrt@dialogue.co> closes #26 closes #100 (superseded) — committed to jasonkuhrt/graphql-request by brikou 4 years ago
Can you try adding
domto yourlibsarray?Example:
For completeness, there are other errors:
You should not include a dom lib to an api project, it may leads to some weird behaviors.
Why was this closed? I’m using
graphql-requestfor testing graphql with Jest in a nodejs API application and I don’t really want to includedomas lib in tsconfig.json.fetchis normally a DOM-only API – this package appears to have an API similar to fetch, but not the same. It’s used like:Maybe the best solution would be to just copy the relevant parts instead of referencing
RequestInit. There’s also Microsoft/TypeScript#15780 which would allow you to pull indomtypings without users needing to modify tsconfig.json, but that then adds a bunch of globals that they might not need.Can a maintainer please look at one of the two PRs open that addresses this issue?
One quick workaround is to update tsconfig.json:
I believe your TS compilation will also be faster.