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

Fix request types for use with Node #578

Merged

Conversation

jliuhtonen
Copy link
Contributor

Screenshot 2024-04-20 at 21 59 11

When using Ky with Node, TypeScript will run into compilation error regarding types required by UndiciRequestInit. This is because @types/node does not yet provide these types, and they are not imported from undici-types either. The latter would not even be possible to keep Ky usable with browsers.

This happened to work in the project, because @sindresorhus/tsconfig includes DOM in the libs section. In most Node applications, the DOM lib should not be there and clashes with Node types. One way to circumvent this is to add skipLibCheck: true to tsconfig.json, but this is not a good solution.

This commit adds the needed types until @types/node imports the missing types and adds them to globals. After that, all "Undici" types from the request types should be removed.

When using Ky with Node, TypeScript will run into compilation error regarding types required by `UndiciRequestInit`. This is because `@types/node` does not yet provide these types, and they are not imported from `undici-types` either. The latter would not even be possible to keep Ky usable with browsers.

This happened to work in the project, because `@sindresorhus/tsconfig` includes `DOM` in the libs section. In most Node applications, the DOM lib should not be there and clashes with Node types. One way to circumvent this is to add `skipLibCheck: true` to `tsconfig.json`, but this is not a good solution.

This commit adds the needed types until `@types/node` imports the missing types and adds them to globals. After that, all "Undici" types from the request types should be removed.
@jliuhtonen
Copy link
Contributor Author

Here is an example of a project not compiling because of the issue fixed in this PR.

@sindresorhus
Copy link
Owner

This commit adds the needed types until @types/node imports the missing types and adds them to globals. After that, all "Undici" types from the request types should be removed.

Can you open an issue on the TS types repo and add a code comment with the link? I like to know that it will eventually be resolved upstream.

Add link to DefinitelyTyped issue with missing exported globals.
@jliuhtonen
Copy link
Contributor Author

@sindresorhus done, I opened a discussion here: DefinitelyTyped/DefinitelyTyped#69408

Code comment also added.

@sindresorhus sindresorhus merged commit 10a4ec7 into sindresorhus:main Apr 22, 2024
1 check passed
@jliuhtonen jliuhtonen deleted the fix/request-types-in-node-project branch April 22, 2024 17:17
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

Successfully merging this pull request may close these issues.

None yet

2 participants