Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-helpers-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-typescript-helpers": patch
---

Preserve tuple arity when deriving readable and writable types.
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import type { Readable, Writable } from "openapi-typescript-helpers";
import { describe, expect, expectTypeOf, test } from "vitest";
import { createObservedClient } from "../helpers.js";
import type { paths } from "./schemas/read-write.js";

describe("readOnly/writeOnly", () => {
test("preserves tuple arity in readable and writable types", () => {
type Tuple = ["a", "b"] | ["a", "b", "c"];

expectTypeOf<Readable<Tuple>>().toEqualTypeOf<Tuple>();
expectTypeOf<Writable<Tuple>>().toEqualTypeOf<Tuple>();
});

describe("deeply nested $Read unwrapping through $Read<Object>", () => {
test("$Read should continue recursion when unwrapping $Read<ObjectWithReadProperties>", async () => {
// This tests the fix for a bug where Readable<$Read<U>> returned U directly
Expand Down
8 changes: 4 additions & 4 deletions packages/openapi-typescript-helpers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ export type Readable<T> =
? never
: T extends $Read<infer U>
? Readable<U>
: T extends (infer E)[]
? Readable<E>[]
: T extends readonly unknown[]
? { [K in keyof T]: Readable<T[K]> }
: T extends object
? { [K in keyof T as NonNullable<T[K]> extends $Write<any> ? never : K]: Readable<T[K]> }
: T;
Expand All @@ -238,8 +238,8 @@ export type Writable<T> =
? never
: T extends $Write<infer U>
? Writable<U>
: T extends (infer E)[]
? Writable<E>[]
: T extends readonly unknown[]
? { [K in keyof T]: Writable<T[K]> }
: T extends object
? { [K in keyof T as NonNullable<T[K]> extends $Read<any> ? never : K]: Writable<T[K]> } & {
[K in keyof T as NonNullable<T[K]> extends $Read<any> ? K : never]?: never;
Expand Down
Loading