Skip to content

fix(typescript): coerce unknown-typed global headers to string in generated SDKs#14331

Open
Swimburger wants to merge 2 commits intomainfrom
devin/1774913960-fix-unknown-header-type
Open

fix(typescript): coerce unknown-typed global headers to string in generated SDKs#14331
Swimburger wants to merge 2 commits intomainfrom
devin/1774913960-fix-unknown-header-type

Conversation

@Swimburger
Copy link
Copy Markdown
Member

@Swimburger Swimburger commented Mar 30, 2026

Description

Refs: polytomic/polytomic-typescript#4

When a global header's valueType in the IR is unknown (e.g. an OpenAPI-imported version header without an explicit schema type), the TypeScript generator produces Supplier<unknown> in BaseClientOptions and unknown in BaseRequestOptions. This causes 114 identical TypeScript compilation errors (Type 'unknown' is not assignable to type 'string | undefined') wherever the header value is assigned in generated client code.

Since HTTP headers are always strings, we coerce unknown-typed headers to string at generation time.

Changes Made

  • Added isUnknownType() helper in BaseClientContextImpl.ts to detect when a header's IR TypeReference is unknown
  • In generateBaseClientOptionsInterface: use string instead of unknown for the header type (both literal and Supplier<T>-wrapped variants)
  • In generateBaseRequestOptionsInterface: same coercion for per-request header overrides
  • In generateBaseIdempotentRequestOptionsInterface: same coercion for idempotency headers
  • Added version 3.60.4 changelog entry

Testing

  • Unit tests added/updated
  • pnpm run check passes (biome lint on 4289 files)
  • No seed test fixture added to validate generated output — reviewer should confirm whether a fixture covering this case is needed

Human Review Checklist

  • No generated output snapshot: This fix was not validated by running the generator against a fixture with a global header typed as unknown. Consider running against the Polytomic API definition or adding a minimal fixture to test-definitions/.
  • Only checks top-level unknown: The isUnknownType check only handles typeReference.type === "unknown". Wrapped variants like optional<unknown> are not coerced. Verify this is sufficient for real-world header definitions.
  • Old generator code path not fixed: The customer's issue is on generator v0.51.7, which uses per-client Options/RequestOptions (not BaseClientOptions). This fix only addresses the current HEAD architecture. The customer would need to upgrade to benefit.

Link to Devin session: https://app.devin.ai/sessions/25af4555f0324078a2c8e5be55d3f207
Requested by: @Swimburger


Open with Devin

…erated SDKs

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

devin-ai-integration[bot]

This comment was marked as resolved.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant