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(js-client): Update method params type to be optional when all param keys are optional #6017

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

CalebBarnes
Copy link
Contributor

Summary

This PR improves the developer experience by addressing issues with parameter typing in the API client:

  • Methods with no parameters (e.g., getCurrentUser) incorrectly required passing something like getCurrentUser(undefined).
  • Methods where all parameters are optional (e.g., listSites) required passing an empty object, even though no parameters were necessary.

These issues are resolved by conditionally setting the params type to either void or void | Params<{...}>, depending on the method's parameter requirements.

Changes

  • Added AreAllOptional type to check if all keys in a type are optional.
  • Added IsPathAndQueryOptional type to check if all parameters for a method are optional.
  • Renamed CombinedCaseParams to Params for better readability in IDEs.
  • Updated params type:
    • void for methods with no parameters.
    • void | Params<{...optional params}> for methods where all parameters are optional.
  • Refactored OperationParams to simplify logic and moved repetitive checks into ExtractPathAndQueryParameters.

Example screenshots

Method with no parameters (getCurrentUser):
image

Method with all optional parameters (listSites):
image


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures
    we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
    something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures
    your code follows our style guide and passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

… necessary

- add type AreAllOptional to check if every key on a type is optional
- add IsPathAndQueryOptional to check if all params on a method are
optional
- allow passing nothing (void) or undefined for method params when there
are no required params
- simplify OperationParams / move some logic to
ExtractPathAndQueryParameters to avoid repeating
@CalebBarnes CalebBarnes marked this pull request as ready for review January 15, 2025 22:56
@CalebBarnes CalebBarnes requested a review from a team as a code owner January 15, 2025 22:56
Copy link
Contributor

@serhalp serhalp left a comment

Choose a reason for hiding this comment

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

LGTM

@kodiakhq kodiakhq bot merged commit ad7715b into main Jan 16, 2025
33 checks passed
@kodiakhq kodiakhq bot deleted the fix/js-client-types-optional-params branch January 16, 2025 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants