You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type definition for the response from client.sideconversations.list is defined as {Promise<{result: Array<{ side_conversations: SideConversation[] }>}>} but returns {Promise<SideConversation[]>}
// Filename src/buggy.tsimportdotenvfrom'dotenv';dotenv.config();import{createClient}from'node-zendesk';constclient=createClient({username: process.env.ZD_USERNAME,token: process.env.ZD_TOKEN,subdomain: process.env.ZD_SUBDOMAIN,});constticketId=1258;(async()=>{try{constsideConversations=awaitclient.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.
The text was updated successfully, but these errors were encountered:
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[]>}
node-zendesk/src/clients/core/sideconversations.js
Lines 125 to 135 in fa069d9
Example Code
Output:
Trying to access the response as observed, using the commented out
console.log(sideConversations[0].id)
a Typescript error blocks script execution:To satisfy TypeScript, the response has to be cast to
unknown
and then to the actual returned structure to access any side conversation properties.Which outputs
3fca482a-9d2e-11ef-93d4-e67ae7fb92cd
as expectedExpected/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.12ts-node
10.9.2Additional Context
I believe this may be an issue with the type definitions of other methods in the
SideConversations
class.The text was updated successfully, but these errors were encountered: