Skip to content

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

@Michael-Xie

Description

@Michael-Xie

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions