typescript icon indicating copy to clipboard operation
typescript copied to clipboard

Typescript throwing error when events for a cron job is of a different format

Open Michael-Xie opened this issue 3 years ago • 1 comments

I am using serverless.ts since the code base is using typescript.

I was planning to use multiple cron schedules for a function or use the serverless-local-schedule plug-in, but typescript would say that the format is incompatible, even though the serverless doc for its yaml equivalent is valid. How can this be fixed?

What I have:

export default {
	handler: `${handlerPath(__dirname)}/handler.main`,
	events: [
		{
			schedule: {
				rate: 'cron(30 5 * * ? *)',
			},
		},
	],
};

The error message:

Cannot load "serverless.ts": Initialization error: TSError: ⨯ Unable to compile TypeScript:
serverless.ts:102:3 - error TS2322: Type '{ handler: string; events: { schedule: { rate: string; }; }[]; }' is not assignable to type '{ name?: string; events?: ({ __schemaWorkaround__: null; } | { schedule: string | { rate: string[]; enabled?: boolean; name?: string; description?: string; input?: string | { body: string; } | { [k: string]: unknown; }; inputPath?: string; inputTransformer?: { ...; }; }; } | ... 20 more ... | { ...; })[]; ... 30 mor...'.
  Types of property 'events' are incompatible.
    Type '{ schedule: { rate: string; }; }[]' is not assignable to type '({ __schemaWorkaround__: null; } | { schedule: string | { rate: string[]; enabled?: boolean; name?: string; description?: string; input?: string | { body: string; } | { [k: string]: unknown; }; inputPath?: string; inputTransformer?: { ...; }; }; } | ... 20 more ... | { ...; })[]'.
      Type '{ schedule: { rate: string; }; }' is not assignable to type '{ __schemaWorkaround__: null; } | { schedule: string | { rate: string[]; enabled?: boolean; name?: string; description?: string; input?: string | { body: string; } | { [k: string]: unknown; }; inputPath?: string; inputTransformer?: { ...; }; }; } | ... 20 more ... | { ...; }'.
        Type '{ schedule: { rate: string; }; }' is not assignable to type '{ schedule: string | { rate: string[]; enabled?: boolean; name?: string; description?: string; input?: string | { body: string; } | { [k: string]: unknown; }; inputPath?: string; inputTransformer?: { inputTemplate: string; inputPathsMap?: { ...; }; }; }; }'.
          Types of property 'schedule' are incompatible.
            Type '{ rate: string; }' is not assignable to type 'string | { rate: string[]; enabled?: boolean; name?: string; description?: string; input?: string | { body: string; } | { [k: string]: unknown; }; inputPath?: string; inputTransformer?: { inputTemplate: string; inputPathsMap?: { ...; }; }; }'.
              Type '{ rate: string; }' is not assignable to type '{ rate: string[]; enabled?: boolean; name?: string; description?: string; input?: string | { body: string; } | { [k: string]: unknown; }; inputPath?: string; inputTransformer?: { inputTemplate: string; inputPathsMap?: { ...; }; }; }'.
                Types of property 'rate' are incompatible.
                  Type 'string' is not assignable to type 'string[]'.

Setup:

  • using serverless v3
  • AWS

Michael-Xie avatar Dec 13 '22 14:12 Michael-Xie

try rate: ['cron(30 5 * * ? *)]

herebebogans avatar Mar 03 '23 01:03 herebebogans