首页 > 解决方案 > 如何使用 TypeScript 为 DynamoDB 定义返回类型?

问题描述

我有:

  let resItem: Schema

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

但我得到:

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

标签: node.jstypescriptamazon-dynamodb

解决方案


如果您检查GetItemOutput 的定义和 PromiseResult定义,您将看到 promise 正在返回一个对象,{Item, ConsumedCapacity, $response}但不仅仅是结果。所以我认为你应该使用PromiseResult作为类型并使用Item属性作为你的结果。


推荐阅读