-
Notifications
You must be signed in to change notification settings - Fork 32
/
test.ts
69 lines (60 loc) · 1.96 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// This code is not executed, only statically analyzed using `tsc --noEmit`
import {
EndpointInterface,
Endpoints,
RequestInterface,
RequestParameters,
Route,
} from "./src/index.js";
const endpoint = {} as EndpointInterface;
function assertString(_: string) {}
function assertNullableString(_: string | null | undefined) {}
function assertArray(_: unknown[]) {}
const assertPaginate = {} as {
<R extends Route>(route: R): Promise<void>;
<R extends RequestInterface>(request: R): Promise<void>;
};
const createIssueOptions = {
owner: "octocat",
repo: "hello-world",
title: "My new issue!",
headers: {
"x-foo": "bar",
},
};
const result = endpoint(
"POST /repos/{owner}/{repo}/issues",
createIssueOptions
);
const resultMerge = endpoint.merge(
"POST /repos/{owner}/{repo}/issues",
createIssueOptions
);
const resultMerge2 = endpoint.merge(createIssueOptions);
assertString(result.headers["x-foo"]);
assertString(resultMerge.title);
assertString(resultMerge.headers["x-foo"]);
assertNullableString(resultMerge2.url);
const test = {} as Endpoints["GET /repos/{owner}/{repo}/issues"]["response"];
assertArray(test.data);
assertString(test.data[0].assignees![0].avatar_url);
const test3 = {} as Endpoints["POST /user/repos"]["parameters"];
assertString(test3.name);
const checkRunsRoute =
"GET /repos/{owner}/{repo}/commits/{ref}/check-runs" as const;
assertPaginate(checkRunsRoute);
const listForRef = {} as {
(
params?: RequestParameters &
Omit<
Endpoints["GET /repos/{owner}/{repo}/commits/{ref}/check-runs"]["parameters"],
"baseUrl" | "headers" | "mediaType"
>
): Promise<Endpoints[typeof checkRunsRoute]["response"]>;
defaults: RequestInterface["defaults"];
endpoint: EndpointInterface<{
url: string;
}>;
};
// octokit.paginate can take `request` method. ref: https://github.com/octokit/plugin-paginate-rest.js/blob/b3fb11e301f9658554e110aeebbd7cbb89b8aad4/README.md?plain=1#L117-L126
assertPaginate(listForRef);