Skip to content

Export Decimal type from Stripe namespace#2703

Merged
mbroshi-stripe merged 2 commits intomasterfrom
mbroshi/export-decimal-type
May 6, 2026
Merged

Export Decimal type from Stripe namespace#2703
mbroshi-stripe merged 2 commits intomasterfrom
mbroshi/export-decimal-type

Conversation

@mbroshi-stripe
Copy link
Copy Markdown
Contributor

@mbroshi-stripe mbroshi-stripe commented May 5, 2026

Why?

Users cannot use Stripe.Decimal as a type annotation (e.g. function takesDecimal(d: Stripe.Decimal)) because TypeScript only sees the companion object value, not the branded type. This forces ugly workarounds like typeof Stripe.Decimal.zero.

What?

  • Added export type Decimal = import('./shared.js').Decimal to the declare namespace Stripe block in both stripe.core.ts and stripe.esm.node.ts
  • Uses an inline import type to avoid the circular definition that a direct re-export would cause (since the class already has a static Decimal property)
  • Updated the type test project to verify Stripe.Decimal works as a type annotation

See Also

Changelog

  • Added Stripe.Decimal as a usable type in the Stripe namespace, enabling type annotations like function takesDecimal(d: Stripe.Decimal).

Users could not use `Stripe.Decimal` as a type annotation because
the namespace only exposed the companion object (value), not the
branded type. This adds an explicit type export using an inline
import to avoid the circular definition that a direct re-export
would cause.

Fixes #2698

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Committed-By-Agent: claude
@mbroshi-stripe mbroshi-stripe marked this pull request as ready for review May 5, 2026 19:53
@mbroshi-stripe mbroshi-stripe requested a review from a team as a code owner May 5, 2026 19:53
Copilot AI review requested due to automatic review settings May 5, 2026 19:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes Stripe.Decimal usable in TypeScript type positions by exporting the branded Decimal type from the Stripe namespace (so Stripe.Decimal works as both a value and a type), and adds a type-test to validate the behavior.

Changes:

  • Exported Decimal as a type within declare namespace Stripe in the ESM typings (stripe.core.ts and stripe.esm.node.ts) using an inline import() type reference.
  • Updated the TypeScript test project to assert Stripe.Decimal works in a parameter type annotation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
testProjects/types/typescriptTest.ts Adds a compile-time check that Stripe.Decimal can be used as a type annotation.
src/stripe.esm.node.ts Exposes Stripe.Decimal as a type within the Stripe namespace for ESM typings.
src/stripe.core.ts Exposes Stripe.Decimal as a type within the core Stripe namespace typings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/stripe.esm.node.ts
@mbroshi-stripe mbroshi-stripe enabled auto-merge (squash) May 6, 2026 17:29
@mbroshi-stripe mbroshi-stripe merged commit dae38ed into master May 6, 2026
9 of 10 checks passed
@mbroshi-stripe mbroshi-stripe deleted the mbroshi/export-decimal-type branch May 6, 2026 17:32
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