Skip to content

Commit 1cd9817

Browse files
nipunn1313djbalin
authored and
Convex, Inc.
committed
convex-backend PR 29: Provide safety and intellisense for weekly cron job (#33124)
Adds `as const` to the `DAYS_OF_WEEK` array to make it literal. This should give type safety/intellisense when filling out `dayOfWeek` in a weekly cron job in `crons.ts`. ---- By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. Co-authored-by: Jan Balin <[email protected]> GitOrigin-RevId: 7b7400324f4b9761253b9ab0a071b0ab94f9f409
1 parent 9556ff8 commit 1cd9817

File tree

1 file changed

+3
-3
lines changed
  • npm-packages/convex/src/server

1 file changed

+3
-3
lines changed

Diff for: npm-packages/convex/src/server/cron.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const DAYS_OF_WEEK = [
3131
"thursday",
3232
"friday",
3333
"saturday",
34-
];
34+
] as const;
3535
type DayOfWeek = (typeof DAYS_OF_WEEK)[number];
3636
/** @public */
3737
export type WeeklySchedule = {
@@ -200,10 +200,10 @@ function validatedDayOfMonth(n: number) {
200200
}
201201

202202
function validatedDayOfWeek(s: string) {
203-
if (typeof s !== "string" || !DAYS_OF_WEEK.includes(s)) {
203+
if (!DAYS_OF_WEEK.includes(s as DayOfWeek)) {
204204
throw new Error('Day of week must be a string like "monday".');
205205
}
206-
return s;
206+
return s as DayOfWeek;
207207
}
208208

209209
function validatedHourOfDay(n: number) {

0 commit comments

Comments
 (0)