Home > front end >  Configuring functionResponseType in typescript serverless template
Configuring functionResponseType in typescript serverless template

Time:07-06

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?

CodePudding user response:

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

  • Related