-
Notifications
You must be signed in to change notification settings - Fork 26
/
task.ts
40 lines (31 loc) · 1.03 KB
/
task.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { DataType } from "../index.js";
import { isDisplayInformation, type DisplayInformation } from './display_information.js'
import { isTrainingInformation, type TrainingInformation } from './training_information.js'
export type TaskID = string
export interface Task<D extends DataType> {
id: TaskID
displayInformation: DisplayInformation
trainingInformation: TrainingInformation<D>
}
export function isTaskID (obj: unknown): obj is TaskID {
return typeof obj === 'string'
}
export function isTask (raw: unknown): raw is Task<DataType> {
if (typeof raw !== 'object' || raw === null) {
return false
}
const { id, displayInformation, trainingInformation }:
Partial<Record<keyof Task<DataType>, unknown>> = raw
if (!isTaskID(id) ||
!isDisplayInformation(displayInformation) ||
!isTrainingInformation(trainingInformation)
) {
return false
}
const _: Task<DataType> = {
id,
displayInformation,
trainingInformation,
} satisfies Record<keyof Task<DataType>, unknown>;
return true
}