Skip to content

fix type checking when strictNullChecks is disabled #1833

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

Merged
merged 2 commits into from
Aug 12, 2024

Conversation

ngraef
Copy link
Contributor

@ngraef ngraef commented Aug 9, 2024

Changes

This PR refactors some types to remove usage of undefined extends T conditional types. It also adds a new test suite that is type checked with strictNullChecks disabled to allow for increased support of that configuration.

Resolves #1778

How to Review

See context in this comment on the issue. Using undefined extends T only behaves as expected when strictNullChecks is enabled. While this configuration is highly recommended for consuming projects, it is not the default, and we should design types that also work without it when possible.

#1778 describes a case where params is required on calls to routes with no parameters defined or no required parameters in the spec. At least two other cases are caused by the same underlying issue:

  1. If all parameter types (query, header, path, and cookie) are defined on a route, params is not required, regardless of whether any of the parameters are required in the spec.
  2. The body property is not required on calls to routes with a required request body defined in the spec.

This PR fixes the behavior of those cases.

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 owner August 9, 2024 20:36
Copy link

changeset-bot bot commented Aug 9, 2024

🦋 Changeset detected

Latest commit: ea2c26b

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

This PR includes changesets to release 3 packages
Name Type
openapi-typescript-helpers Patch
openapi-react-query Patch
openapi-fetch Patch

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

---
"openapi-typescript-helpers": patch
"openapi-react-query": patch
"openapi-fetch": patch
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I view this as a bug fix that implements the expected behavior. However, it does have the potential to break type checking in projects with incorrect code, so I can change this to minor if we want to be safe.

@kerwanp kerwanp added openapi-ts Relevant to the openapi-typescript library openapi-fetch Relevant to the openapi-fetch library openapi-react-query Relevant to openapi-react-query labels Aug 10, 2024
Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

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

Great fix, and great tests, thank you!

@drwpow
Copy link
Contributor

drwpow commented Aug 12, 2024

Shoot looks like another PR merged before this caused some conflicts. Once the conflicts are resolved, happy to merge & release.

@ngraef ngraef force-pushed the fix-required-params branch from 8e46c42 to ea2c26b Compare August 12, 2024 15:28
@ngraef ngraef requested a review from drwpow August 12, 2024 15:31
@drwpow drwpow merged commit cec023d into openapi-ts:main Aug 12, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openapi-fetch Relevant to the openapi-fetch library openapi-react-query Relevant to openapi-react-query openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

params always required
3 participants