Skip to content

fix(openapi-fetch): don't rely on DOM types - #1827

Merged
drwpow merged 1 commit into
openapi-ts:mainfrom
ngraef:fix-headers-type
Aug 7, 2024
Merged

fix(openapi-fetch): don't rely on DOM types#1827
drwpow merged 1 commit into
openapi-ts:mainfrom
ngraef:fix-headers-type

Conversation

@ngraef

@ngraefngraef commented Aug 7, 2024

Copy link
Copy Markdown
Contributor

Changes

This PR changes typing to avoid the global HeadersInit, which is declared in the DOM lib and therefore typically not included in Node projects.

Resolves#1823
Resolves#1824
Resolves#1735

How to Review

How can a reviewer review your changes? What should be kept in mind for this review?

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

@ngraef
ngraef requested a review from a team as a code ownerAugust 7, 2024 18:08
@changeset-bot

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 19887b0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
NameType
openapi-fetchPatch
openapi-react-queryPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR


export type HeadersOptions =
| HeadersInit
| Required<RequestInit>["headers"]

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change pulls a reference to HeadersInit from RequestInit rather than relying on the global declaration, which only exists in the DOM lib. In projects with the DOM lib, this reference will resolve to HeadersInit declared in lib.dom.d.ts. In projects with Node types and no DOM lib, this reference will resolve to HeadersInit from undici-types/fetch.d.ts as referenced from @types/node/globals.d.ts.

@drwpowdrwpow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing! I agree with this logic. And here, existing tests will work. Thank you for improving!

@drwpow
drwpow merged commit ba0d595 into openapi-ts:mainAug 7, 2024
@github-actionsgithub-actionsBot mentioned this pull request Aug 7, 2024
Sign up for freeto 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.

Invalid types using @tsconfig/node20 [openapi-fetch] HeadersInit support in Node.JS Cannot find name 'HeadersInit'.

2 participants

@ngraef@drwpow