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

Improve TS Types #429

Merged
merged 2 commits into from
Nov 26, 2024
Merged

Improve TS Types #429

merged 2 commits into from
Nov 26, 2024

Conversation

dugjason
Copy link
Contributor

@dugjason dugjason commented Oct 13, 2024

Pull Request Description

Resolves issues with return types on most GET / PUT / PATCH / POST requests.

Most of the endpoints look like this;

  /**
   * Retrieve details for multiple tickets based on their IDs.
   * @param {Array<number>} ticketIds - An array of ticket IDs to fetch.
   * @returns {Promise<Array<Ticket>>} An array of ticket details.
   * @see {@link https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#show-multiple-tickets}
   * @example
   * const ticketsDetails = await client.tickets.showMany([123, 456, 789]);
   */
  async showMany(ticketIds) {
    return this.get(['tickets', 'show_many', {ids: ticketIds}]);
  }

This indicates that you can access your list of tickets by calling

const tickets = await client.showMany([1,2,3])
for (const ticket of tickets) {
   ...
}

Problem is that the data actually returned from the this.get() call is returned as;

{
  response: {
    json: [Function: json],
    status: 200,
    headers: { get: [Function: get] },
    statusText: 'OK'
  },
  result: [{
    id: 12345,
    ...
  }],
}

This should ensure that folks can more reliably use this client with Typescript.

This also fixes a typo in the macros.js file; this.gettAll( -> this.getAll(


Related Issue(s)

  • This PR fixes/closes issue Mismatched types #398
  • This is a new feature and does not have an associated issue.

Additional Information

  • This change is a breaking change (may require a major version update)
    (This will fix/break(?) types returned. I would expect TS folks are using something like const ticketsRes = await showMany() as {response: object, result: Ticket[]} given that trying to access tickets as it was previously typed would fail)
  • This change is a new feature (non-breaking change which adds functionality)
  • This change improves the code (e.g., refactoring, etc.)
  • This change includes dependency updates

Test Cases

Include any test cases or steps you took to test your changes. If you have added new functionality, please include relevant unit tests.


Documentation

  • I have updated the documentation accordingly.
  • No updates are required.

Checklist

  • I have read the CONTRIBUTING documentation.
  • My code follows the coding standards of this project.
  • All new and existing tests passed.

@dugjason dugjason marked this pull request as ready for review October 14, 2024 05:19
Copy link
Owner

@blakmatrix blakmatrix left a comment

Choose a reason for hiding this comment

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

Awesome thanks so much! you rock!

@blakmatrix blakmatrix merged commit c4b6107 into blakmatrix:master Nov 26, 2024
2 checks passed
Sign up for free to 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.

2 participants