Type definitions

Below are TypeScript type definitions for all of the classes and methods available in the Val Town runtime environment.

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* eslint-disable */
declare global {
/**
* `Interval` is the first argument to a scheduled val.
`lastRunAt` is useful for polling a data source *since* the last time the val ran. It is `undefined` on the first time the scheduled val runs.
```ts
interface Interval {
lastRunAt: Date | undefined;
}
```
*/
interface Interval {
id: string;
delay: number;
author: string;
registeredAt: Date;
clearedAt: Date | undefined;
lastRunAt: Date | undefined;
}
/**
* `Email` is the first argument to an email handler val. It represents the email that triggered the val.
```ts
interface Email {
from: string,
to: string,
cc: string,
bcc: string,
subject: string | undefined,
text: string | undefined,
html: string | undefined,
}
```
*/
interface Email {
from: string,
to: string,
cc: string,
bcc: string,
subject: string | undefined,
text: string | undefined,
html: string | undefined,
}
interface ParsedQs {
[key: string]: undefined | string | string[] | ParsedQs | ParsedQs[];
}
namespace express {
interface Request {
get(name: "set-cookie"): string[] | undefined;
get(name: string): string | undefined;
header(name: "set-cookie"): string[] | undefined;
header(name: string): string | undefined;
is(type: string | string[]): string | false | null;
protocol: string;
secure: boolean;
ip: string;
ips: string[];
subdomains: string[];
path: string;
hostname: string;
host: string;
fresh: boolean;
stale: boolean;
xhr: boolean;
body: any;
cookies: any;
method: string;
params: Record<string, string>;
query: ParsedQs;
signedCookies: any;
originalUrl: string;
baseUrl: string;
}
interface Response {
status(code: number): this;
send(body?: any): this;
json(body?: any): this;
jsonp(body?: any): this;
type(type: string): this;
set(field: any): this;
set(field: string, value?: string | string[]): this;
get(field: string): string | undefined;
redirect(url: string): void;
redirect(status: number, url: string): void;
redirect(url: string, status: number): void;
end(cb?: () => void): this;
end(chunk: any, cb?: () => void): this;
end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
}
}
type JsonPrimitive = string | number | boolean | null;
type JsonObject = { [Key in string]: JsonValue } & {
[Key in string]?: JsonValue | undefined;
};
type JsonValue = JsonPrimitive | JsonObject | JsonArray;