Skip to content

[openapi-fetch] HeadersInit support in Node.JS #1823

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

Closed
1 task
JohanAlteruna opened this issue Aug 6, 2024 · 0 comments · Fixed by #1827
Closed
1 task

[openapi-fetch] HeadersInit support in Node.JS #1823

JohanAlteruna opened this issue Aug 6, 2024 · 0 comments · Fixed by #1827
Labels
enhancement New feature or request openapi-fetch Relevant to the openapi-fetch library

Comments

@JohanAlteruna
Copy link

JohanAlteruna commented Aug 6, 2024

Description

When using this library in a backend (e.g. for testing HTTP servers), it is reasonable to assume Node might be used (it works fine during runtime since Node supports the Fetch API). Currently, the generics used by this library rely on the HeadersInit type which is available in some TS environments but not others (the lib option in the TSConfig file seems to determine this; it looks like it is available if lib has 'DOM' in it). The @types/node package declares the Headers type, but not HeadersInit. The HeadersInit type seemingly becomes unresolved if @types/node is used but not the 'DOM' lib.

Proposal

I think this problem could be solved by removing the dependency of this package on the 'DOM' lib by altering the tsconfig file. The HeadersInit type could be defined as follows:

type HeadersInit = NonNullable<
  ConstructorParameters<typeof Headers>[0]
>;

Then again, the Headers type and other fetch types do need to come from somewhere. I'm not sure what would be most appropriate; maybe they could be bundled with the declaration files somehow.

Checklist

@JohanAlteruna JohanAlteruna added enhancement New feature or request openapi-fetch Relevant to the openapi-fetch library labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant