-
Notifications
You must be signed in to change notification settings - Fork 733
/
json-types.test.ts
55 lines (49 loc) · 1.35 KB
/
json-types.test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { JSONValue, JSONObject, JSONArray } from "json-types";
interface Contact2 {
firstName: string;
lastName: string;
middleName?: string;
salutation?: string;
email?: string;
phones: {
[k: string]: string | undefined;
};
addresses: {
[k: string]:
| {
street: string;
city: string;
state: string;
postalCode: string | number;
country: string;
houseNumber: number;
}
| undefined;
};
}
const c: Contact2 = {} as any;
c.phones.foo; // $ExpectType string | undefined
function isJSONValue(val: JSONValue) {}
function isJSONArray(val: JSONArray) {}
function isJSONObject(val: JSONObject) {}
isJSONValue([]);
isJSONValue(4);
isJSONValue("abc");
isJSONValue(false);
isJSONValue({ hello: ["world"] });
isJSONValue(() => 3); // $ExpectError
isJSONArray([]);
isJSONArray(["abc", 4]);
isJSONArray(4); // $ExpectError
isJSONArray("abc"); // $ExpectError
isJSONArray(false); // $ExpectError
isJSONArray({ hello: ["world"] }); // $ExpectError
isJSONArray(() => 3); // $ExpectError
isJSONObject([]); // $ExpectError
isJSONObject(["abc", 4]); // $ExpectError
isJSONObject(4); // $ExpectError
isJSONObject("abc"); // $ExpectError
isJSONObject(false); // $ExpectError
isJSONObject({ hello: ["world"] });
isJSONObject({ 3: ["hello, world"] });
isJSONObject(() => 3); // $ExpectError