Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Michael-Xie opened this issue Dec 13, 2022 · 1 comment

Comments

@Michael-Xie
Copy link

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
@herebebogans
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants