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

Response type definition for client.sideconversations.list incorrect #435

Open
terriann opened this issue Nov 12, 2024 · 0 comments
Open
Labels

Comments

@terriann
Copy link

Describe the Bug

The type definition for the response from client.sideconversations.list is defined as {Promise<{result: Array<{ side_conversations: SideConversation[] }>}>} but returns {Promise<SideConversation[]>}

/**
* List all the Side Conversations tickets.
* @param {number} ticketID - the Id of the ticket.
* @returns {Promise<{result: Array<{ side_conversations: SideConversation[] }>}>} An array of tickets.
* @see https://developer.zendesk.com/api-reference/ticketing/side_conversation/side_conversation/#list-side-conversations
* @example
* const tickets = await client.sideconversations.list(123);
*/
async list(ticketID) {
return this.getAll(['tickets', ticketID, 'side_conversations']);
}

Example Code

// Filename src/buggy.ts
import dotenv from 'dotenv';
dotenv.config();
import { createClient } from 'node-zendesk';

const client = createClient( {
	username: process.env.ZD_USERNAME,
	token: process.env.ZD_TOKEN,
	subdomain: process.env.ZD_SUBDOMAIN,
});

const ticketId = 1258;

(async () => {
  try {
	  const sideConversations = await client.sideconversations.list(ticketId);
	  console.log(sideConversations.result);
	  console.log(sideConversations);
	  //console.log(sideConversations[0].id);
  } catch (error) {
    console.error('Error fetching side conversations:', error);
  }
})();

Output:

undefined
[
  {
    url: 'https://subdomain.zendesk.com/api/v2/tickets/1258/side_conversations/3fca482a-9d2e-11ef-93d4-e67ae7fb92cd',
    id: '3fca482a-9d2e-11ef-93d4-e67ae7fb92cd',
    ticket_id: 1258,
    subject: '#test-channel',
    preview_text: 'Reopening',
    state: 'closed',
    participants: [ [Object], [Object] ],
    created_at: '2024-11-07T17:32:23.605Z',
    updated_at: '2024-11-07T17:50:40.648Z',
    message_added_at: '2024-11-07T17:50:17.700Z',
    state_updated_at: '2024-11-07T17:50:38.966Z',
    external_ids: {
      slackThreadTimestamp: '1731000744.059469',
      slackThreadAnchorTimestamp: '1731000744.529909'
    }
  },
  {
    url: 'https://subdomain.zendesk.com/api/v2/tickets/1258/side_conversations/3763cebd-9d2e-11ef-ac88-375efb053d42',
    id: '3763cebd-9d2e-11ef-ac88-375efb053d42',
    ticket_id: 1258,
    subject: '#test-channel',
    preview_text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut sapien urna, mattis ut massa vitae, feugiat vestibulum elit. Phasellus malesuada ornare nisi sed sollicitudin. Nullam tempor fringilla velit, sit amet iaculis massa consequat vel. Quisque sagittis vitae augue vel dapibus',
    state: 'closed',
    participants: [ [Object], [Object] ],
    created_at: '2024-11-07T17:32:09.510Z',
    updated_at: '2024-11-07T17:50:40.128Z',
    message_added_at: '2024-11-07T17:32:35.270Z',
    state_updated_at: '2024-11-07T17:32:49.104Z',
    external_ids: {
      slackThreadTimestamp: '1731000729.974209',
      slackThreadAnchorTimestamp: '1731000730.507559'
    }
  }
]

Trying to access the response as observed, using the commented out console.log(sideConversations[0].id) a Typescript error blocks script execution:

$ npx ts-node src/buggy.ts
TSError: ⨯ Unable to compile TypeScript:
src/buggy.ts:19:16 - error TS7053: Element implicitly has an 'any' type because expression of type '0' can't be used to index type '{ result: { side_conversations: SideConversation[]; }[]; }'.
  Property '0' does not exist on type '{ result: { side_conversations: SideConversation[]; }[]; }'.

19    console.log(sideConversations[0].id);

To satisfy TypeScript, the response has to be cast to unknown and then to the actual returned structure to access any side conversation properties.

...
	  const sideConversations = await client.sideconversations.list(ticketId) as unknown as SideConversation[];
	  console.log(sideConversations[0].id);
...

Which outputs 3fca482a-9d2e-11ef-93d4-e67ae7fb92cd as expected

Expected/Actual Behavior

As described above, the output from that method returns as expected. However, because the type definition is incorrect, the response has to be cast to a different type to use that method; otherwise, TypeScript errors are thrown.

Environment Information

  • node-zendesk version: 5.0.12
  • Node.js version: v22.11.0
  • Operating System: Mac OS
  • Any other relevant software versions?
    • ts-node 10.9.2

Additional Context

I believe this may be an issue with the type definitions of other methods in the SideConversations class.

@terriann terriann added the bug label Nov 12, 2024
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

1 participant