I'm sending a message to an SQS queue as follows in typescript:
const queueName = 'some_queue_name';
const foo = 'foo';
const bar = 'bar';
const sqs = new AWS.SQS();
const SendMessageRequest: AWS.SQS.SendMessageRequest = {
MessageBody: JSON.stringify({ foo, bar }),
QueueUrl: queueName,
};
try {
const request = sqs.sendMessage(SendMessageRequest, function (err, data) {
if (err) {
console.log('Error', err);
}
});
const smgResponse: SendMessageResult = await request.promise();
} catch (err) {
console.log(err);
expect(err).toBeUndefined();
}
At runtime, the SendMessageRequest
shows a $response
property but this isn't visible in the object definition. What is the best way to access this property at runtime?
Use a type assertion:
Replace
unknown
with whatever type$response
is at runtime.If you are doing a lot of assertions you could create a new type for this: