Skip to content

Commit

Permalink
feat: GetResponseTypeFromEndpointMethod and `GetResponseDataTypeFro…
Browse files Browse the repository at this point in the history
…mEndpointMethod` helpers (#32)
  • Loading branch information
gr2m authored Apr 8, 2020
1 parent 01a5e67 commit 27412f2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@

## Usage

Get response types from endpoint methods

```ts
import {
GetResponseTypeFromEndpointMethod,
GetResponseDataTypeFromEndpointMethod,
} from "@octokit/types";
import { Octokit } from "@octokit/rest";

const octokit = new Octokit();
type CreateLabelResponseType = GetResponseType<
typeof octokit.issues.createLabel
>;
type CreateLabelResponseDataType = GetResponseDataType<
typeof octokit.issues.createLabel
>;
```

See https://octokit.github.io/types.ts for all exported types

## Contributing
Expand Down
9 changes: 9 additions & 0 deletions src/GetResponseTypeFromEndpointMethod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type Unwrap<T> = T extends Promise<infer U> ? U : T;
type AnyFunction = (...args) => any;

export type GetResponseTypeFromEndpointMethod<T extends AnyFunction> = Unwrap<
ReturnType<T>
>;
export type GetResponseDataTypeFromEndpointMethod<
T extends AnyFunction
> = Unwrap<ReturnType<T>>["data"];
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from "./Signal";
export * from "./StrategyInterface";
export * from "./Url";
export * from "./VERSION";
export * from "./GetResponseTypeFromEndpointMethod";

0 comments on commit 27412f2

Please # to comment.