Skip to content

Commit

Permalink
Test headers type inference
Browse files Browse the repository at this point in the history
  • Loading branch information
mpppk committed Oct 20, 2024
1 parent a424263 commit e37253d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions examples/fastify/zod/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const main = async () => {
const r = await res.json();
console.log(`${path}:${method} => ${r.userId}`);
console.log(res.headers.get("Content-Type"));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const contentType: "application/json" = res.headers.get("Content-Type");
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const hasContentType: true = res.headers.has("Content-Type");
} else {
// e is the response schema defined in pathMap["/users"]["post"].res other than "20X"
const e = await res.text();
Expand Down
4 changes: 2 additions & 2 deletions examples/spec/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { z } from "zod";
import { ToApiEndpoints, ZodApiEndpoints } from "../../src";

const JsonHeader = z.union([
z.object({ "content-type": z.string() }),
z.object({ "Content-Type": z.string() }),
z.object({ "content-type": z.literal("application/json") }),
z.object({ "Content-Type": z.literal("application/json") }),
]);
export const pathMap = {
"/users": {
Expand Down

0 comments on commit e37253d

Please sign in to comment.