Skip to content

Commit 7f75fa9

Browse files
committed
Fix lint errors and add a changeset
1 parent 6722c97 commit 7f75fa9

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

.changeset/gold-worms-wave.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"openapi-typescript-helpers": patch
3+
"openapi-fetch": patch
4+
---
5+
6+
Fix data/error discrimination when there are empty-body errors

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,23 @@ export type FetchOptions<T> = RequestOptions<T> &
115115
export type FetchResponse<T, O, Media extends MediaType> =
116116
| {
117117
data: ParseAsResponse<
118-
GetValueWithDefault<SuccessResponse<ResponseObjectMap<T>>, Media, Record<string, never>>,
118+
GetValueWithDefault<
119+
SuccessResponse<ResponseObjectMap<T>>,
120+
Media,
121+
Record<string, never>
122+
>,
119123
O
120124
>;
121125
error?: never;
122126
response: Response;
123127
}
124128
| {
125129
data?: never;
126-
error: GetValueWithDefault<ErrorResponse<ResponseObjectMap<T>>, Media, Record<string, never>>;
130+
error: GetValueWithDefault<
131+
ErrorResponse<ResponseObjectMap<T>>,
132+
Media,
133+
Record<string, never>
134+
>;
127135
response: Response;
128136
};
129137

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ interface Blogpost {
1111
publish_date?: number | undefined;
1212
}
1313

14+
// This is a type test that will not be executed
15+
// eslint-disable-next-line vitest/expect-expect
1416
test("the error type works properly", async () => {
1517
const value = await GET("/blogposts");
1618

1719
if (value.data) {
1820
expectTypeOf(value.data).toEqualTypeOf<Array<Blogpost>>();
1921
} else {
2022
expectTypeOf(value.data).toBeUndefined();
21-
expectTypeOf(value.error).extract<{ code: number }>().toEqualTypeOf<{ code: number; message: string }>();
22-
expectTypeOf(value.error).exclude<{ code: number }>().toEqualTypeOf<Record<string, never>>();
23+
expectTypeOf(value.error)
24+
.extract<{ code: number }>()
25+
.toEqualTypeOf<{ code: number; message: string }>();
26+
expectTypeOf(value.error)
27+
.exclude<{ code: number }>()
28+
.toEqualTypeOf<Record<string, never>>();
2329
}
2430
});

0 commit comments

Comments
 (0)