Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types error in index.d.ts for nodejs #35

Closed
KyloJorgensen opened this issue Jan 5, 2019 · 7 comments
Closed

Types error in index.d.ts for nodejs #35

KyloJorgensen opened this issue Jan 5, 2019 · 7 comments

Comments

@KyloJorgensen
Copy link

image

usesing vscode to write nodejs server code

@lquixada
Copy link
Owner

lquixada commented Feb 2, 2019

I'm not familiar with Typescript but I think fetch, Request, Response and Headers are supposed to be global types, aren't they?

In my VSCode, there's no such warning.

@lquixada
Copy link
Owner

Closing this since there was no answer.

@esetnik
Copy link

esetnik commented Mar 6, 2019

@lquixada please reopen. I have the same error as @KyloJorgensen. I don't think those are global types. I don't see them defined in the node type definitions at least.

/builds/x/api/node_modules/cross-fetch/index.d.ts (1,27): Cannot find name 'fetch'.
/builds/x/api/node_modules/cross-fetch/index.d.ts (2,27): Cannot find name 'Request'.
/builds/x/api/node_modules/cross-fetch/index.d.ts (3,27): Cannot find name 'Response'.
/builds/x/api/node_modules/cross-fetch/index.d.ts (4,31): Cannot find name 'Headers'. Did you mean 'headers'?

@lquixada
Copy link
Owner

hey @esetnik, can you try going to your tsconfig.json > compilerOptions > libs and add "dom" to the list?

@lquixada lquixada reopened this Mar 16, 2019
@will-wow
Copy link

I was seeing the same issue - import fetch from "cross-fetch"; wasn't picking up any types for fetch, and the index.d.ts file showed Cannot find name 'fetch'.

Adding dom to libs fixed the issue for me. Thanks @lquixada!

@esetnik
Copy link

esetnik commented Mar 21, 2019

I don't think dom should be added to libs for node environments. This adds a lot of types that are only available in the browser.

@lquixada
Copy link
Owner

@esetnik you're right! however, if you follow the the fetch, Request, Response and Header declaration inside the lib.dom.d.ts, you'll realize that those are very deeply nested declarations. Unfortunately, there's no easy way to extract and maintain them. It would be needed a lot of copy and paste and it would be hard to keep track of any update.

In my opinion, having a single source of truth (the lib.dom.d.ts in this case) is more valuable than saving a few kilobytes that users would not have to download anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants