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

Mismatched types #398

Open
zomchak-code opened this issue Dec 15, 2023 · 6 comments
Open

Mismatched types #398

zomchak-code opened this issue Dec 15, 2023 · 6 comments
Labels

Comments

@zomchak-code
Copy link

Describe the Bug
Types are not matching actual values returned

Example Code

const ticket = await client.tickets.show(392005);
console.log({ id: ticket.id, response: ticket.response });

Screenshot 2023-12-15 at 00 26 43

Expected Behavior
Either .id reported as type error or following output:

{
  id: 392005,
  response: undefined
}

Actual Behavior
Either .resource reported as type error and following output:

{
  id: undefined,
  response: {
    json: [Function: json],
    status: 200,
    headers: {
      get: [Function: get]
    },
    statusText: "OK"
  }
}

Environment Information

  • node-zendesk version: 5.0.7
  • Node.js version: 20.2.0
  • Operating System: MacOS
  • Any other relevant software versions?
@mackstann
Copy link

mackstann commented Jan 19, 2024

I'm seeing something similar with the TS types. I'm making a users.createOrUpdate call. The types say it returns a Promise<User>. But when the promise resolves, I don't have a User, I have a wrapper object with response and result properties. result is of type User.

Paste of the method declaration in 5.0.9 from my node_modules:

    /**
     * Creates or updates a user.
     * @param {object} user - The user details.
     * @returns {Promise<User>} The created or updated user's details.
     * @async
     * @see {@link https://developer.zendesk.com/api-reference/ticketing/users/users/#create-or-update-user}
     * @example
     * const user = await client.users.createOrUpdate({name: 'John Doe', email: 'john@example.com'});
     */
    createOrUpdate(user: object): Promise<User>;

And the original JS declaration in the repo:

/**
* Creates or updates a user.
* @param {object} user - The user details.
* @returns {Promise<User>} The created or updated user's details.
* @async
* @see {@link https://developer.zendesk.com/api-reference/ticketing/users/users/#create-or-update-user}
* @example
* const user = await client.users.createOrUpdate({name: 'John Doe', email: 'john@example.com'});
*/
async createOrUpdate(user) {
return this.post(['users', 'create_or_update'], user);
}

Paste of the actual resolved value:

{
  response: {
    json: [Function: json],
    status: 201,
    headers: { get: [Function: get] },
    statusText: 'Created'
  },
  result: {
    id: ...,
    ... other User properties ...
  }
}

@binarypie
Copy link

binarypie commented Mar 26, 2024

I have the same issue with users.show where it expects to return a Promise<User> but the actual response value is Promise<{result: User}>

@jckw
Copy link

jckw commented Apr 2, 2024

I just contributed to the bounty on this issue.

Each contribution to this bounty has an expiry time and will be auto-refunded to the contributor if the issue is not solved before then.

Current bounty reward

To make this a public bounty or have a reward split, the maintainer can reply to this comment.

@owenshaupt
Copy link

ditto — exactly what @mackstann is seeing returned is also returning for me when using users.update

@andoshin11
Copy link

any update on this?

@pano9000
Copy link

pano9000 commented Jul 9, 2024

having the same issue with users.update.
If I recall correctly also similar thing with organizations.showMany was happening, where the types expect an array of numbers, while in reality it also seems to correctly accept a single number, not in an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants