From faac9a2f800ec9ec467ced7b44f94e0f4a0184a0 Mon Sep 17 00:00:00 2001 From: sliterok Date: Thu, 19 Dec 2019 11:28:52 +0500 Subject: [PATCH] Update Task.ts You should warn about task id being string in Task constructor itself instead of silently converting, because in TaskTimer.remove() method of it would throw an error in case when user would provide any other type than string. --- src/Task.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Task.ts b/src/Task.ts index fafbe09..9adfa94 100644 --- a/src/Task.ts +++ b/src/Task.ts @@ -351,6 +351,10 @@ class Task { if (!options || !options.id) { throw new Error('A unique task ID is required.'); } + + if(typeof options.id !== 'string') { + throw new Error('Task ID must be a string'); + } if (typeof options.callback !== 'function') { throw new Error('A callback function is required for a task to run.'); @@ -368,7 +372,7 @@ class Task { ...DEFAULT_TASK_OPTIONS }; - this._.id = String(options.id); + this._.id = options.id; this._.callback = options.callback; this._.startDate = options.startDate || null; this._.stopDate = options.stopDate || null;