在打字稿无服务器模板中配置functionResponseType

发布于 2025-02-13 11:13:34 字数 1362 浏览 0 评论 0 原文

我正在尝试在无服务器框架模板中配置 functionResponseType (为了使用部分批处理响应)。

这是我对所讨论函数的事件声明:

    events: [
        {
            sqs: {
                arn: {
                    'Fn::GetAtt': [
                        'TheQueue',
                        'Arn'
                    ]
                },
                batchSize: 40,
                maximumBatchingWindow: 10,
                functionResponseType: "ReportBatchItemFailures",
            },
        },
    ],

这是类型声明文件中的SQS块的样子:(

{
    sqs:
        | AwsArnString
        | {
            arn: AwsArn;
            batchSize?: number;
            enabled?: boolean;
            maximumBatchingWindow?: number;
            functionResponseType?: "ReportBatchItemFailures";
            filterPatterns?: FilterPatterns;
          };
}

源在这里:

noreferrer“ > 不编译,带有以下错误:

属性“ functionResponseType”的类型是不兼容的。键入'字符串'不能分配给'reportbatchitemfailures'''。ts(2322)

如果我删除 function> function> functionResponseType 属性属性模板填充了,并且函数按预期部署(但是没有部分SQS响应)功能)。

我不是打字稿的专家,所以我有点被困在这里。我在做什么错?

I am trying to configure functionResponseType in a TypeScript Serverless framework template (in order to make use of partial batch responses).

This is my event declaration for the function in question:

    events: [
        {
            sqs: {
                arn: {
                    'Fn::GetAtt': [
                        'TheQueue',
                        'Arn'
                    ]
                },
                batchSize: 40,
                maximumBatchingWindow: 10,
                functionResponseType: "ReportBatchItemFailures",
            },
        },
    ],

This is what the sqs block looks like in the type declaration file:

{
    sqs:
        | AwsArnString
        | {
            arn: AwsArn;
            batchSize?: number;
            enabled?: boolean;
            maximumBatchingWindow?: number;
            functionResponseType?: "ReportBatchItemFailures";
            filterPatterns?: FilterPatterns;
          };
}

(The source is here: https://github.com/serverless/typescript/blob/master/index.d.ts#L534-L543)

When I include the functionResponseType property, the template does not compile, with the following error:

Types of property 'functionResponseType' are incompatible. Type 'string' is not assignable to type '"ReportBatchItemFailures"'.ts(2322)

If I remove the functionResponseType property the template compiles fine and the function deploys as expected (but then without the partial SQS response functionality).

I am no TypeScript guru, so I am sort of stuck here. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何必那么矫情 2025-02-20 11:13:34

您可以使用“ reportbatchitemfailures”作为const 使其键入安全

You can use "ReportBatchItemFailures" as const to make it type safe

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文