Rather than fetchMessages always returning union of FetchMessagesWithActionsResponse and FetchMessagesForChannelsResponse, you can use the value of the includeMessageActions flag in FetchMessagesParameters to narrow the response type like so:
fetchMessages(parameters: History.FetchMessagesParameters & {includeMessageActions: true}): Promise<History.FetchMessagesWithActionsResponse>;
fetchMessages(parameters: History.FetchMessagesParameters & {includeMessageActions?: false}): Promise<History.FetchMessagesForChannelsResponse>;
Rather than
fetchMessagesalways returning union ofFetchMessagesWithActionsResponseandFetchMessagesForChannelsResponse, you can use the value of theincludeMessageActionsflag inFetchMessagesParametersto narrow the response type like so: