Skip to content

Commit 8011bd3

Browse files
kostyshcode-xhyun
authored andcommitted
fix: Added missing template types for returned s in the method.
1 parent d8b4c04 commit 8011bd3

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/pulse/schedule.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import { Job, JobAttributesData } from '../job';
44

55
const debug = createDebugger('pulse:schedule');
66

7-
export type ScheduleMethod = <T extends JobAttributesData>(
8-
when: string | Date,
9-
names: string | string[],
10-
data?: T
11-
) => Promise<Job | Job[]>;
127
/**
138
* Schedule a job or jobs at a specific time
149
* @name Pulse#schedule
@@ -18,15 +13,20 @@ export type ScheduleMethod = <T extends JobAttributesData>(
1813
* @param data data to send to job
1914
* @returns job or jobs created
2015
*/
21-
export const schedule: ScheduleMethod = function schedule(this: Pulse, when, names, data) {
16+
export const schedule = function schedule<T extends JobAttributesData>(
17+
this: Pulse,
18+
when: string | Date,
19+
names: string | string[],
20+
data?: T,
21+
) {
2222
/**
2323
* Internal method that creates a job with given date
2424
* @param when when the job gets run
2525
* @param name of job to run
2626
* @param data data to send to job
2727
* @returns instance of new job
2828
*/
29-
const createJob = async <T extends JobAttributesData>(when: string | Date, name: string, data: T): Promise<Job> => {
29+
const createJob = async <T extends JobAttributesData>(when: string | Date, name: string, data: T): Promise<Job<T>> => {
3030
const job = this.create(name, data);
3131

3232
await job.schedule(when).save();
@@ -45,9 +45,9 @@ export const schedule: ScheduleMethod = function schedule(this: Pulse, when, nam
4545
when: string | Date,
4646
names: string[],
4747
data: T
48-
): Promise<Job[]> => {
48+
): Promise<Job<T>[]> => {
4949
try {
50-
const createJobList: Array<Promise<Job>> = [];
50+
const createJobList: Array<Promise<Job<T>>> = [];
5151
names.map((name) => createJobList.push(createJob(when, name, data)));
5252
debug('Pulse.schedule()::createJobs() -> all jobs created successfully');
5353
return Promise.all(createJobList);
@@ -59,7 +59,7 @@ export const schedule: ScheduleMethod = function schedule(this: Pulse, when, nam
5959

6060
if (typeof names === 'string') {
6161
debug('Pulse.schedule(%s, %O, [%O], cb)', when, names);
62-
return createJob(when, names, data || {});
62+
return createJob(when, names, data || {} as T);
6363
}
6464

6565
if (Array.isArray(names)) {
@@ -69,3 +69,5 @@ export const schedule: ScheduleMethod = function schedule(this: Pulse, when, nam
6969

7070
throw new TypeError('Name must be string or array of strings');
7171
};
72+
73+
export type ScheduleMethod = typeof schedule;

0 commit comments

Comments
 (0)