Skip to content

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

Closed
@JohanAlteruna

Description

@JohanAlteruna

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestopenapi-fetchRelevant to the openapi-fetch library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions