|
1 | 1 | // Copyright 2021 Twitter, Inc.
|
2 | 2 | // SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
4 |
| -type SuccessStatus = 200; |
5 |
| -type ResponseType = "application/json"; |
| 4 | +export type SuccessStatus = 200 | 201; |
| 5 | +export type ResponseType = "application/json"; |
6 | 6 |
|
7 | 7 | export interface AuthHeader {
|
8 | 8 | Authorization: string;
|
@@ -33,18 +33,22 @@ export type UnionToIntersection<U> = (
|
33 | 33 | ? I
|
34 | 34 | : never;
|
35 | 35 |
|
| 36 | +export type GetSuccess<T> = { |
| 37 | + [K in SuccessStatus & keyof T]: GetContent<T[K]>; |
| 38 | +}[SuccessStatus & keyof T]; |
| 39 | + |
36 | 40 | export type TwitterResponse<T> = UnionToIntersection<ExtractTwitterResponse<T>>;
|
37 | 41 |
|
38 |
| -export type ExtractTwitterResponse<T> = "responses" extends keyof T |
39 |
| - ? SuccessStatus extends keyof T["responses"] |
40 |
| - ? "content" extends keyof T["responses"][SuccessStatus] |
41 |
| - ? ResponseType extends keyof T["responses"][SuccessStatus]["content"] |
42 |
| - ? T["responses"][SuccessStatus]["content"][ResponseType] |
43 |
| - : never |
44 |
| - : never |
| 42 | +export type GetContent<T> = "content" extends keyof T |
| 43 | + ? ResponseType extends keyof T["content"] |
| 44 | + ? T["content"][ResponseType] |
45 | 45 | : never
|
46 | 46 | : never;
|
47 | 47 |
|
| 48 | +export type ExtractTwitterResponse<T> = "responses" extends keyof T |
| 49 | + ? GetSuccess<T["responses"]> |
| 50 | + : never; |
| 51 | + |
48 | 52 | export type TwitterParams<T> = "parameters" extends keyof T
|
49 | 53 | ? "query" extends keyof T["parameters"]
|
50 | 54 | ? T["parameters"]["query"]
|
|
0 commit comments