node.jstypescriptamazon-dynamodb

How to define a return type for a DynamoDB get with TypeScript?


I have:

  let resItem: Schema

  resItem = await dynamoClient.get({
    TableName,
    Key: {
      uuid: request.body.uuid
    }
  }).promise()

but I get:

Type 'PromiseResult<GetItemOutput, AWSError>' is missing the following properties from type 'Schema': uuid, topics, phoneNumber, timezonets(2739)

Solution

  • If you check the definition of GetItemOutput and the definition of PromiseResult you will see that the promise is returning an object of {Item, ConsumedCapacity, $response} but not the result only. So I think you should use PromiseResult as the type and use the Item attribute as your result.