From 25527bb1d75dbd3349ae2746e1d56a695e33904b Mon Sep 17 00:00:00 2001 From: Gustavo Valverde Date: Fri, 20 Mar 2026 07:35:12 +0000 Subject: [PATCH] fix: make Endpoint properties readonly and fix OpenAPI schema types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two type-level fixes that affect consumers using strict TypeScript: 1. Make `options` and `path` on `Endpoint` type readonly. These properties were mutable, making type parameters like `Meta` invariant. This prevented concrete endpoint types (e.g., `Endpoint<..., { SERVER_ONLY: true }, ...>`) from being assigned to index signatures using bare `Endpoint`. Making them readonly makes `Meta`, `Method`, and `Path` covariant (read-only positions only), fixing the variance issue. 2. Add explicit `| undefined` to optional properties in `OpenAPIParameter.schema`. With `exactOptionalPropertyTypes: true`, `format?: string` means "absent or string" but NOT "explicitly undefined". When endpoints infer `format` as `string | undefined` (e.g., from optional zod fields), this causes a type mismatch. Adding `| undefined` makes the types compatible under strict optional property checking. Runtime behavior is unchanged — these are type-level-only fixes. --- packages/better-call/src/endpoint.ts | 8 ++++---- packages/better-call/src/openapi.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/better-call/src/endpoint.ts b/packages/better-call/src/endpoint.ts index fcb4851..96a9525 100644 --- a/packages/better-call/src/endpoint.ts +++ b/packages/better-call/src/endpoint.ts @@ -252,11 +252,11 @@ export type Endpoint< ( context?: InputContext, ): Promise>; - options: Omit & { - method: Method; - metadata?: Meta; + readonly options: Omit & { + readonly method: Method; + readonly metadata?: Meta; }; - path: Path; + readonly path: Path; }; // Path + options + handler overload diff --git a/packages/better-call/src/openapi.ts b/packages/better-call/src/openapi.ts index c71c037..366ffb1 100644 --- a/packages/better-call/src/openapi.ts +++ b/packages/better-call/src/openapi.ts @@ -16,15 +16,15 @@ export interface OpenAPIParameter { required?: boolean; schema?: { type: OpenAPISchemaType; - format?: string; + format?: string | undefined; items?: { type: OpenAPISchemaType; }; enum?: string[]; minLength?: number; - description?: string; - default?: string; - example?: string; + description?: string | undefined; + default?: string | undefined; + example?: string | undefined; }; }