强制转换对象文字

时间:2019-07-23 05:47:25

标签: typescript

我有以下代码导出const

export const sqsEventMock : SQSEvent = {
  Records: [
    {
      body: 'sample body',
      messageAttributes: {
        EventType: {
          dataType: 'String',
          stringValue: 'MyCustomEvent'
        },
        StreamName: {
          dataType: 'String',
          stringValue: 'input-stream'
        },
        version: 1337,
        correlationId: 'fake-correlation-id',
        source: 'fake-source'
      }
    }
  ]
};

但是,我无法强制将此const强制转换为AWS中的SQSEvent。我当然可以公开函数而不是直接const,但是无论如何我还是喜欢这样做。有谁知道如何做到这一点。我不能在这里使用Partial,因为代码后还有另一种方法,它需要使用SQSEvent而不是Partial<SQSEvent>

0 个答案:

没有答案