Skip to content

fix: CJS companion namespace access for resource types at all depths#2765

Merged
jar-stripe merged 3 commits into
masterfrom
jar/cjs-export-map
Jun 24, 2026
Merged

fix: CJS companion namespace access for resource types at all depths#2765
jar-stripe merged 3 commits into
masterfrom
jar/cjs-export-map

Conversation

@jar-stripe

@jar-stripe jar-stripe commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Why?

CJS consumers can't access nested type namespaces like Stripe.Price.Recurring, Stripe.Billing.Alert.Status, or Stripe.Terminal.Configuration.Tipping. The CJS declaration file uses flat type aliases inside declare namespace StripeConstructor, which drops companion namespaces that ESM carries automatically via export { X }.

Additionally, nested resource types (under product namespaces like Billing, Terminal, Apps, etc.) were broken in both ESM and CJS because companion namespace blocks were rendered nested under the product namespace instead of at module scope where they merge with the interface.

After this change, all type paths that work in ESM also work in CJS.

What?

  • Resource files: companion namespaces now render at module scope (export namespace Alert { ... }) instead of nested under the product namespace (export namespace Billing { export namespace Alert { ... } })
  • CJS declaration file: companion namespace blocks now emitted for resource sub-types (e.g. Price.Recurring, Alert.Status) at all depths
  • CJS declaration file: params companion blocks now emitted at full depth (previously only 1 level)
  • Internal references in resource files updated (e.g. Billing.Alert.StatusAlert.Status)

See Also

Changelog

  • Fixes TypeScript type access for nested namespaces in CJS mode (e.g. Stripe.Price.Recurring, Stripe.Subscription.BillingMode)
  • Fixes TypeScript type access for nested resource types e.g. Stripe.Billing.Alert.Status, Stripe.Terminal.Configuration.Tipping in both ESM and CJS modes.

jar-stripe and others added 2 commits June 23, 2026 18:12
Regenerated from stripe/sdk-codegen#3768 which fixes:
- Resource sub-types (e.g. Stripe.Price.Recurring) now accessible in CJS
- Nested resource types (e.g. Stripe.Billing.Alert.Status) now accessible
  in both CJS and ESM
- Deep params namespaces (e.g. AccountCreateParams.BusinessProfile.AnnualRevenue)
  now accessible in CJS

Fixes #2683

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
Adds type assertions for patterns that were previously broken in CJS
(and some in ESM too):
- Resource sub-types: Stripe.Price.Recurring, Stripe.Customer.InvoiceSettings
- Deep resource sub-types: Stripe.Subscription.BillingMode.Type
- Nested resource sub-types: Stripe.Billing.Alert.Status,
  Stripe.Terminal.Configuration.Tipping, Stripe.Apps.Secret.Scope
- Deep params: Stripe.AccountCreateParams.BusinessProfile.AnnualRevenue

Added to both testProjects/types/ (ESM) and testProjects/types-cjs-node16/
(CJS) so both declaration files are covered.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude

@xavdid xavdid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! had a comment about more test coverage, but looks good otherwise

Comment thread testProjects/types-cjs-node16/typescriptTest.ts
Comment thread src/resources/Checkout/Sessions.ts
@jar-stripe jar-stripe marked this pull request as ready for review June 24, 2026 04:33
@jar-stripe jar-stripe requested a review from a team as a code owner June 24, 2026 04:33
@jar-stripe jar-stripe requested review from Copilot and kidus-stripe and removed request for a team June 24, 2026 04:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

Same coverage as types/ and types-cjs-node16/ — covers
module: commonjs / moduleResolution: node resolution mode.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
@jar-stripe jar-stripe enabled auto-merge (squash) June 24, 2026 04:46
@jar-stripe jar-stripe merged commit 4c5c311 into master Jun 24, 2026
11 checks passed
@jar-stripe jar-stripe deleted the jar/cjs-export-map branch June 24, 2026 04:49
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.

3 participants