-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Endpoints with no responses can only be '302', according to TypeScript #188
Comments
Just sharing my debugging as I've to run I was able to reproduce the problem with a TypeScript playground The (by the way, you should use The REST API docs state that there can be either a
When looking at Here is a good starting point for further investigation: https://github.com/octokit/types.ts/blob/359fe757707bab4e9d1911108205154049c5385c/src/generated/Endpoints.ts#L61 |
I can confirm that this is still an issue with the latest version of I will be looking into this and #334 |
After a brief look, for the type ExtractOctokitResponse<R> = "responses" extends keyof R // condition is true
? SuccessResponseDataType<R["responses"]> extends never // condition is true
? RedirectResponseDataType<R["responses"]> extends never // condition is false
? EmptyResponseDataType<R["responses"]>
: RedirectResponseDataType<R["responses"]> // <== returned value from condition
: SuccessResponseDataType<R["responses"]>
: unknown; It seems that the current implementation cannot handle cases where there is no body for many status codes like in this case. The value returned by So we need to somehow make a type that can go through all the status codes defined for an endpoint and return an |
I made some modifications and managed to get the issue fixed, though I am unsure if it will have unintended consequences diff --git a/src/generated/Endpoints.ts b/src/generated/Endpoints.ts
index c0d68f4..358e6eb 100644
--- a/src/generated/Endpoints.ts
+++ b/src/generated/Endpoints.ts
@@ -60,7 +60,7 @@ type MethodsMap = {
};
type SuccessStatuses = 200 | 201 | 202 | 204;
type RedirectStatuses = 301 | 302;
-type EmptyResponseStatuses = 201 | 204;
+type EmptyResponseStatuses = 201 | 204 | 302;
type KnownJsonResponseTypes =
| "application/json"
| "application/scim+json"
@@ -88,9 +88,9 @@ type DataType<T> = {
}[KnownJsonResponseTypes & keyof T];
type ExtractOctokitResponse<R> = "responses" extends keyof R
? SuccessResponseDataType<R["responses"]> extends never
- ? RedirectResponseDataType<R["responses"]> extends never
- ? EmptyResponseDataType<R["responses"]>
- : RedirectResponseDataType<R["responses"]>
+ ? EmptyResponseDataType<R["responses"]> extends never
+ ? RedirectResponseDataType<R["responses"]>
+ : EmptyResponseDataType<R["responses"]>
: SuccessResponseDataType<R["responses"]>
: unknown; The tests in the |
Checklist
Environment
Versions
19.0.4
What happened?
Got an TS error
Minimal test case to reproduce the problem
What did you expect to happen?
204 should be a valid response status
What the problem might be
Bad types?
The text was updated successfully, but these errors were encountered: