nanobar
nanobar

Reputation: 66435

Typescript Cannot dynamically import whatwg-fetch

Typescript has built in defs for whatwg-fetch now (I'm using v2.7), however it ignores them with dynamic imports:

import(/* webpackChunkName: "whatwg-fetch" */ 'whatwg-fetch')

TS7016: Could not find a declaration file for module 'whatwg-fetch'. 'C:/../node_modules/whatwg-fetch/fetch.js' implicitly has an 'any' type. Try npm install @types/whatwg-fetch if it exists or add a new declaration (.d.ts) file containing declare module 'whatwg-fetch';

However if I install that the @types/whatwg-fetch type module as it suggests it has dozens of errors about duplicate definitions due to already having it built in...

How can I circumvent this issue? Thanks

Upvotes: 0

Views: 1274

Answers (1)

nanobar
nanobar

Reputation: 66435

I've solved this by created a d.ts file - whatwg-fetch.d.ts with this inside:

declare module "whatwg-fetch";

Upvotes: 1

Related Questions