-
-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix type discrimination for non-overlapping content types (#1610)
* Add a failing type test for `openapi-fetch` * Actually fix the issue * Fix lint errors and add a changeset
- Loading branch information
Showing
6 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"openapi-typescript-helpers": patch | ||
"openapi-fetch": patch | ||
--- | ||
|
||
Fix data/error discrimination when there are empty-body errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { test, expectTypeOf } from "vitest"; | ||
|
||
import createClient from "../src/index.js"; | ||
import type { paths } from "./fixtures/api.js"; | ||
|
||
const { GET } = createClient<paths>(); | ||
|
||
interface Blogpost { | ||
title: string; | ||
body: string; | ||
publish_date?: number | undefined; | ||
} | ||
|
||
// This is a type test that will not be executed | ||
// eslint-disable-next-line vitest/expect-expect | ||
test("the error type works properly", async () => { | ||
const value = await GET("/blogposts"); | ||
|
||
if (value.data) { | ||
expectTypeOf(value.data).toEqualTypeOf<Array<Blogpost>>(); | ||
} else { | ||
expectTypeOf(value.data).toBeUndefined(); | ||
expectTypeOf(value.error) | ||
.extract<{ code: number }>() | ||
.toEqualTypeOf<{ code: number; message: string }>(); | ||
expectTypeOf(value.error) | ||
.exclude<{ code: number }>() | ||
.toEqualTypeOf<Record<string, never>>(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters