Skip to content

Commit 6cba82b

Browse files
committed
Fix TS errors
1 parent 60516f8 commit 6cba82b

File tree

16 files changed

+393
-271
lines changed

16 files changed

+393
-271
lines changed

.changeset/unlucky-pumpkins-march.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-fetch": patch
3+
---
4+
5+
Fix type errors

packages/openapi-fetch/examples/nextjs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"react-dom": "18.2.0"
1313
},
1414
"devDependencies": {
15-
"@types/node": "20.11.19",
15+
"@types/node": "20.11.24",
1616
"@types/react": "18.2.20",
1717
"@types/react-dom": "18.2.7",
1818
"openapi-typescript": "workspace:^",

packages/openapi-fetch/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"version": "pnpm run prepare && pnpm run build"
6464
},
6565
"dependencies": {
66+
"@types/node": "^20.11.24",
6667
"openapi-typescript-helpers": "^0.0.7"
6768
},
6869
"devDependencies": {
@@ -74,7 +75,7 @@
7475
"openapi-typescript-fetch": "^1.1.3",
7576
"superagent": "^8.1.2",
7677
"typescript": "^5.3.3",
77-
"vitest": "^1.2.2",
78+
"vitest": "^1.3.1",
7879
"vitest-fetch-mock": "^0.2.2"
7980
}
8081
}

packages/openapi-fetch/src/index.d.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type {
22
ErrorResponse,
3-
SuccessResponse,
43
FilterKeys,
4+
HasRequiredKeys,
5+
HttpMethod,
56
MediaType,
7+
OperationRequestBodyContent,
68
PathsWithMethod,
79
ResponseObjectMap,
8-
OperationRequestBodyContent,
9-
HasRequiredKeys,
10+
SuccessResponse,
1011
} from "openapi-typescript-helpers";
1112

1213
// Note: though "any" is considered bad practice in general, this library relies
@@ -80,7 +81,7 @@ type BodyType<T = unknown> = {
8081
stream: Response["body"];
8182
};
8283
export type ParseAs = keyof BodyType;
83-
export type ParseAsResponse<T, O extends FetchOptions> = O extends {
84+
export type ParseAsResponse<T, O> = O extends {
8485
parseAs: ParseAs;
8586
}
8687
? BodyType<T>[O["parseAs"]]
@@ -110,13 +111,7 @@ export type RequestBodyOption<T> =
110111
export type FetchOptions<T> = RequestOptions<T> &
111112
Omit<RequestInit, "body" | "headers">;
112113

113-
/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */
114-
export type MaybeOptionalInit<P extends {}, M extends keyof P> =
115-
HasRequiredKeys<FetchOptions<FilterKeys<P, M>>> extends never
116-
? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
117-
: [FetchOptions<FilterKeys<P, M>>];
118-
119-
export type FetchResponse<T, O extends FetchOptions> =
114+
export type FetchResponse<T, O> =
120115
| {
121116
data: ParseAsResponse<
122117
FilterKeys<SuccessResponse<ResponseObjectMap<T>>, MediaType>,
@@ -174,7 +169,19 @@ export interface Middleware {
174169
onResponse?: typeof onResponse;
175170
}
176171

177-
export type ClientMethod<Paths extends {}, M> = <
172+
/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */
173+
export type MaybeOptionalInit<
174+
P extends Record<HttpMethod, {}>,
175+
M extends keyof P,
176+
> =
177+
HasRequiredKeys<FetchOptions<FilterKeys<P, M>>> extends never
178+
? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
179+
: [FetchOptions<FilterKeys<P, M>>];
180+
181+
export type ClientMethod<
182+
Paths extends Record<string, Record<HttpMethod, {}>>,
183+
M extends HttpMethod,
184+
> = <
178185
P extends PathsWithMethod<Paths, M>,
179186
I extends MaybeOptionalInit<Paths[P], M>,
180187
>(

packages/openapi-fetch/test/index.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
21
// @ts-expect-error
32
import createFetchMock from "vitest-fetch-mock";
43
import createClient, {

packages/openapi-fetch/test/v7-beta.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
21
// @ts-expect-error
32
import createFetchMock from "vitest-fetch-mock";
43
import createClient, {

packages/openapi-fetch/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"moduleResolution": "NodeNext",
1010
"noUncheckedIndexedAccess": true,
1111
"outDir": "dist",
12-
"skipLibCheck": true,
12+
"skipLibCheck": false,
1313
"strict": true,
1414
"target": "ESNext",
1515
"types": ["vitest/globals"]
1616
},
1717
"include": ["src", "test"],
18-
"exclude": ["node_modules"]
18+
"exclude": ["examples", "node_modules"]
1919
}

packages/openapi-typescript-helpers/index.d.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ export type OperationRequestBodyMediaContent<T> =
5858
? FilterKeys<NonNullable<OperationRequestBody<T>>, "content"> | undefined
5959
: FilterKeys<OperationRequestBody<T>, "content">;
6060
/** Return first `content` from a Request Object Mapping, allowing any media type */
61-
export type OperationRequestBodyContent<T> = FilterKeys<
62-
OperationRequestBodyMediaContent<T>,
63-
MediaType
64-
> extends never
65-
?
66-
| FilterKeys<NonNullable<OperationRequestBodyMediaContent<T>>, MediaType>
67-
| undefined
68-
: FilterKeys<OperationRequestBodyMediaContent<T>, MediaType>;
61+
export type OperationRequestBodyContent<T> =
62+
FilterKeys<OperationRequestBodyMediaContent<T>, MediaType> extends never
63+
?
64+
| FilterKeys<
65+
NonNullable<OperationRequestBodyMediaContent<T>>,
66+
MediaType
67+
>
68+
| undefined
69+
: FilterKeys<OperationRequestBodyMediaContent<T>, MediaType>;
6970
/** Return first 2XX response from a Response Object Map */
7071
export type SuccessResponse<T> = ResponseContent<FilterKeys<T, OkStatus>>;
7172
/** Return first 5XX or 4XX response (in that order) from a Response Object Map */
@@ -97,4 +98,5 @@ export type FindRequiredKeys<T, K extends keyof T> = K extends unknown
9798
? never
9899
: K
99100
: K;
101+
/** Does this object contain required keys? */
100102
export type HasRequiredKeys<T> = FindRequiredKeys<T, keyof T>;

packages/openapi-typescript/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@
6262
"typescript": "^5.x"
6363
},
6464
"dependencies": {
65-
"@redocly/openapi-core": "^1.9.0",
65+
"@redocly/openapi-core": "^1.10.3",
6666
"ansi-colors": "^4.1.3",
6767
"supports-color": "^9.4.0",
6868
"yargs-parser": "^21.1.1"
6969
},
7070
"devDependencies": {
7171
"@types/degit": "^2.8.6",
7272
"@types/js-yaml": "^4.0.9",
73-
"@types/node": "^20.11.19",
73+
"@types/node": "^20.11.24",
7474
"degit": "^2.8.4",
7575
"del-cli": "^5.1.0",
76-
"esbuild": "^0.20.0",
76+
"esbuild": "^0.20.1",
7777
"execa": "^7.2.0",
7878
"typescript": "^5.3.3",
79-
"vite-node": "^1.2.2",
80-
"vitest": "^1.2.2"
79+
"vite-node": "^1.3.1",
80+
"vitest": "^1.3.1"
8181
}
8282
}

packages/openapi-typescript/test/index.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { fileURLToPath } from "node:url";
2+
import { beforeAll, describe, expect, test, vi } from "vitest";
23
import openapiTS, { astToString } from "../src/index.js";
34
import type { OpenAPI3, OpenAPITSOptions } from "../src/types.js";
45
import type { TestCase } from "./test-helpers.js";
@@ -692,7 +693,7 @@ export type operations = Record<string, never>;`,
692693
);
693694
}
694695

695-
it("does not mutate original reference", async () => {
696+
test("does not mutate original reference", async () => {
696697
const schema: OpenAPI3 = {
697698
openapi: "3.1",
698699
info: { title: "test", version: "1.0" },

0 commit comments

Comments
 (0)