forked from FOSS/BangleApps
Tweaks to sched.d.ts to type-check the docs example
[The docs example](https://github.com/espruino/BangleApps/tree/master/apps/sched#internals--library)master
parent
8a65bc9c7b
commit
566400b26c
|
@ -9,30 +9,67 @@ declare module Sched {
|
||||||
SAT = 64,
|
SAT = 64,
|
||||||
}
|
}
|
||||||
|
|
||||||
type VibratePattern = "." | "," | "-" | ":" | ";" | "=";
|
type Dows = number;
|
||||||
|
type Milliseconds = number;
|
||||||
|
|
||||||
|
// slight hack - all objects have a `on()`, this unions with that type so we can add it to an object
|
||||||
|
type OnBoolean<T extends boolean = boolean>
|
||||||
|
= T | Object["on"];
|
||||||
|
|
||||||
|
type VibratePattern = string; // "." | "," | "-" | ":" | ";" | "="
|
||||||
|
|
||||||
|
type DateString = `${number}-${number}-${number}`;
|
||||||
|
|
||||||
|
type NewSched = {
|
||||||
|
msg?: string,
|
||||||
|
appid?: string,
|
||||||
|
dow?: Dows,
|
||||||
|
on?: OnBoolean<false>,
|
||||||
|
js?: string,
|
||||||
|
} & (NewTimer | NewAlarm);
|
||||||
|
|
||||||
|
type NewTimer = { timer: number };
|
||||||
|
type NewAlarm = { t: number, date?: DateString };
|
||||||
|
|
||||||
|
type DefaultSched = {
|
||||||
|
on: OnBoolean<true>,
|
||||||
|
del: boolean,
|
||||||
|
rp: false,
|
||||||
|
as: false,
|
||||||
|
dow: Dows,
|
||||||
|
last: number,
|
||||||
|
vibrate: VibratePattern,
|
||||||
|
};
|
||||||
|
|
||||||
|
type DefaultAlarm = DefaultSched & { t: number };
|
||||||
|
|
||||||
|
type DefaultTimer = DefaultSched & { timer: number };
|
||||||
|
|
||||||
type Sched = {
|
type Sched = {
|
||||||
id?: string,
|
// from NewSched / set in setAlarm()
|
||||||
appid?: string,
|
|
||||||
on: boolean,
|
|
||||||
dow?: number,
|
|
||||||
msg: string,
|
msg: string,
|
||||||
last: number,
|
appid?: string,
|
||||||
|
dow: Dows,
|
||||||
|
on: OnBoolean,
|
||||||
|
timer?: Milliseconds, // this is a timer
|
||||||
|
|
||||||
|
// setAlarm adds:
|
||||||
|
id: string,
|
||||||
|
t: Milliseconds, // time of day since midnight (in ms)
|
||||||
|
|
||||||
|
// optional NewSched
|
||||||
vibrate?: VibratePattern,
|
vibrate?: VibratePattern,
|
||||||
hidden?: boolean,
|
hidden?: boolean,
|
||||||
as?: boolean, // auto snooze
|
as?: boolean, // auto snooze
|
||||||
del?: boolean,
|
del?: boolean,
|
||||||
js?: string,
|
js?: string,
|
||||||
data?: unknown,
|
data?: unknown,
|
||||||
|
|
||||||
|
// set by sched
|
||||||
|
last?: number,
|
||||||
} & (
|
} & (
|
||||||
{
|
{
|
||||||
t: number, // time of day since midnight (in ms, set automatically when timer starts)
|
date: DateString,
|
||||||
} | {
|
|
||||||
timer: number, // this is a timer - the time in ms
|
|
||||||
}
|
|
||||||
) & (
|
|
||||||
{
|
|
||||||
date: `${number}-${number}-${number}`,
|
|
||||||
rp?: Repeat,
|
rp?: Repeat,
|
||||||
} | {
|
} | {
|
||||||
date: undefined,
|
date: undefined,
|
||||||
|
@ -62,18 +99,18 @@ declare module Sched {
|
||||||
|
|
||||||
function getAlarm(id: string): Sched | undefined;
|
function getAlarm(id: string): Sched | undefined;
|
||||||
|
|
||||||
function getActiveAlarms (alarms: Sched[], time?: Date): Sched[];
|
function getActiveAlarms(alarms: Sched[], time?: Date): Sched[];
|
||||||
|
|
||||||
function setAlarm(id: string, alarm?: Sched): void;
|
function setAlarm(id: string, alarm?: NewSched): void;
|
||||||
|
|
||||||
function getTimeToAlarm(alarm: Sched, time?: Date): number | undefined;
|
function getTimeToAlarm(alarm: Sched | undefined | null, time?: Date): number | undefined;
|
||||||
function getTimeToAlarm(alarm?: undefined | null, time?: Date): undefined;
|
function getTimeToAlarm(alarm?: undefined | null, time?: Date): undefined;
|
||||||
|
|
||||||
function reload(): void;
|
function reload(): void;
|
||||||
|
|
||||||
function newDefaultAlarm(): Sched;
|
function newDefaultAlarm(): DefaultAlarm;
|
||||||
|
|
||||||
function newDefaultTimer(): Sched;
|
function newDefaultTimer(): DefaultTimer;
|
||||||
|
|
||||||
function getSettings(): SchedSettings;
|
function getSettings(): SchedSettings;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue