Skip to content

fix(openapi-typescript): guard Readable/Writable against branded primitive types#2766

Open
deej-io wants to merge 1 commit intoopenapi-ts:mainfrom
deej-io:fix/readable-writable-branded-primitives
Open

fix(openapi-typescript): guard Readable/Writable against branded primitive types#2766
deej-io wants to merge 1 commit intoopenapi-ts:mainfrom
deej-io:fix/readable-writable-branded-primitives

Conversation

@deej-io
Copy link
Copy Markdown

@deej-io deej-io commented Apr 13, 2026

Fixes #2765

string & { __brand: "UserId" } satisfies T extends object, so Readable<T> and Writable<T> were mapping over all primitive prototype methods instead of returning the type as-is.

Adds T extends string | number | boolean | bigint | symbol ? T : before the extends object branch in both types. Applied to openapi-typescript-helpers/src/index.ts and READ_WRITE_HELPER_TYPES in src/transform/index.ts.

@deej-io deej-io requested a review from a team as a code owner April 13, 2026 16:38
@deej-io deej-io requested a review from gzm0 April 13, 2026 16:38
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 13, 2026

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit a863f27

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 13, 2026

⚠️ No Changeset found

Latest commit: a863f27

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

…itive types

`string & { __brand: "UserId" }` satisfies `extends object`, so Readable/Writable
was mapping over all string prototype methods instead of returning the type as-is.

Adds a primitive guard before `extends object` in both types. Fix applied to both
READ_WRITE_HELPER_TYPES in src/transform/index.ts and openapi-typescript-helpers.
@deej-io deej-io force-pushed the fix/readable-writable-branded-primitives branch from d06e072 to a863f27 Compare April 13, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Readable/Writable breaks branded primitive types (string & {...}, number & {...})

1 participant