File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 8
8
9
9
## Usage
10
10
11
+ Get response types from endpoint methods
12
+
13
+ ``` ts
14
+ import {
15
+ GetResponseTypeFromEndpointMethod ,
16
+ GetResponseDataTypeFromEndpointMethod ,
17
+ } from " @octokit/types" ;
18
+ import { Octokit } from " @octokit/rest" ;
19
+
20
+ const octokit = new Octokit ();
21
+ type CreateLabelResponseType = GetResponseType <
22
+ typeof octokit .issues .createLabel
23
+ >;
24
+ type CreateLabelResponseDataType = GetResponseDataType <
25
+ typeof octokit .issues .createLabel
26
+ >;
27
+ ```
28
+
11
29
See https://octokit.github.io/types.ts for all exported types
12
30
13
31
## Contributing
Original file line number Diff line number Diff line change
1
+ type Unwrap < T > = T extends Promise < infer U > ? U : T ;
2
+ type AnyFunction = ( ...args ) => any ;
3
+
4
+ export type GetResponseTypeFromEndpointMethod < T extends AnyFunction > = Unwrap <
5
+ ReturnType < T >
6
+ > ;
7
+ export type GetResponseDataTypeFromEndpointMethod <
8
+ T extends AnyFunction
9
+ > = Unwrap < ReturnType < T > > [ "data" ] ;
Original file line number Diff line number Diff line change @@ -16,3 +16,4 @@ export * from "./Signal";
16
16
export * from "./StrategyInterface" ;
17
17
export * from "./Url" ;
18
18
export * from "./VERSION" ;
19
+ export * from "./GetResponseTypeFromEndpointMethod" ;
You can’t perform that action at this time.
0 commit comments