Skip to content

Commit

Permalink
fix: pluging schema merger type
Browse files Browse the repository at this point in the history
  • Loading branch information
Bekacru committed Jul 25, 2024
1 parent 23e310e commit 7c83e6e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/better-fetch/src/create-fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from "zod";
import { betterFetch } from "../fetch";
import { BetterFetchPlugin } from "../plugins";
import type { BetterFetchOption } from "../types";
import { methods } from "./schema";
import { createSchema, methods } from "./schema";
import type { BetterFetch, CreateFetchOption } from "./types";

const applySchemaPlugin = (config: CreateFetchOption) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/better-fetch/src/create-fetch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
export type PluginSchema<P> = P extends BetterFetchPlugin
? P["schema"] extends Schema
? P["schema"]
: undefined
: undefined;
: {}
: {};

export type MergeSchema<Options extends CreateFetchOption> =
Options["plugins"] extends Array<infer P>
Expand Down
24 changes: 24 additions & 0 deletions packages/better-fetch/src/test/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,28 @@ describe("plugin", () => {
}),
);
});

it("shouldn't break the type on plugin with no schema plugin a schema defined", async () => {
const f = createFetch({
plugins: [
{
id: "test",
name: "Test",
},
],
schema: createSchema(
{
"/path": {
output: z.object({
message: z.string(),
}),
},
},
{
strict: true,
},
),
});
expectTypeOf(f).parameter(0).toMatchTypeOf<"/path">();
});
});

0 comments on commit 7c83e6e

Please sign in to comment.