fix(client): loosen opaque promise outputs

This commit is contained in:
Dax Raad 2026-07-11 16:36:49 -04:00
commit 1956497f42
3 changed files with 135 additions and 114 deletions

View file

@ -827,7 +827,7 @@ function structuralTypes(schemas: ReadonlyArray<Schema.Top>, mutable: boolean, r
const output = type
.replaceAll(/ & Brand\.Brand<"[^"]+">/g, "")
.replaceAll("Schema.Json", "JsonValue")
.replaceAll(/(?<!["'])\bunknown\b(?!["'])/g, "JsonValue")
.replaceAll(/(?<!["'])\bunknown\b(?!["'])/g, "any")
return mutable ? mutableType(output) : output
}
return {

View file

@ -1097,6 +1097,27 @@ describe("HttpApiCodegen.generate", () => {
expect(output.operations[0]?.success).toBe("stream")
})
test("emits opaque Promise SSE fields as any", () => {
const output = emitPromise(
compileContract(
api(
HttpApiEndpoint.get("subscribe", "/event", {
success: HttpApiSchema.StreamSse({
data: Schema.Struct({
metadata: Schema.Record(Schema.String, Schema.Unknown),
label: Schema.Literal("unknown"),
}),
}),
}),
),
),
)
const types = output.files.find((file) => file.path === "types.ts")?.content
expect(types).toContain('readonly "metadata": { readonly [x: string]: any }')
expect(types).toContain('readonly "label": "unknown"')
})
test("preserves annotated stream response statuses", () => {
const output = compile(
api(