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
28 changes: 0 additions & 28 deletions src/Decimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,6 @@ export interface DecimalRoundingOptions {
/**
* Built-in rounding presets keyed by semantic name.
*
* @remarks
* This is an **open interface** — consumers can extend it via declaration
* merging to register custom presets that are accepted by
* {@link DecimalImpl.round}:
*
* ```ts
* declare module '@stripe/apps-extensibility-sdk/stdlib' {
* interface DecimalRoundingPresets {
* 'my-custom-preset': DecimalRoundingOptions;
* }
* }
* ```
*
* Built-in presets:
*
* | Preset | Equivalent DecimalRoundingOptions |
Expand Down Expand Up @@ -1011,21 +998,6 @@ class DecimalImpl {
* prevents accidental assignment from plain `number`, `string`, or
* `bigint`.
*
* Create values via the companion object:
*
* @example
* ```ts
* import { Decimal, RoundDirection } from '@stripe/apps-extensibility-sdk/stdlib';
*
* const price = Decimal.from('19.99');
* const tax = price.mul(Decimal.from('0.0825'));
* const total = price.add(tax);
*
* console.log(total.toFixed(2, 'half-up')); // "21.64"
* console.log(JSON.stringify({ total })); // '{"total":"21.639175"}'
* console.log(total.toFixed(2, 'half-even')); // "21.64"
* ```
*
* @public
*/
export type Decimal = DecimalImpl & {
Expand Down
7 changes: 7 additions & 0 deletions src/stripe.cjs.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Create a callable wrapper for backward compatibility
// eslint-disable-next-line func-style
const StripeConstructor = function(
this: any,

Check warning on line 10 in src/stripe.cjs.node.ts

View workflow job for this annotation

GitHub Actions / Static Checks

Argument 'this' should be typed with a non-any type
key: string,
config?: Record<string, unknown>
): Stripe {
Expand All @@ -34,4 +34,11 @@
});
}
}
// Re-export the Decimal type so that CJS consumers can use
// Stripe.Decimal as a type (e.g., `const d: Stripe.Decimal`).
// Without this, `export =` only carries the function signature, not the
// merged namespace from stripe.core.ts.
declare namespace StripeConstructor {
export type Decimal = import('./shared.js').Decimal;
}
export = StripeConstructor;
Comment on lines +42 to 44
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

This change is meant to enable Stripe.Decimal in type positions for CJS consumers, but there doesn’t appear to be a TypeScript compile-time test that exercises the CJS require('stripe') typing path (e.g., const Stripe = require('stripe'); const d: Stripe.Decimal = Stripe.Decimal.from('1.0');). Adding a type test would prevent regressions.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's no existing CJS TypeScript test project — only a plain JS one. Adding a CJS TS test project is tracked separately. The ESM type tests cover Stripe.Decimal as a type annotation.

2 changes: 2 additions & 0 deletions src/stripe.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,8 @@ export declare namespace Stripe {
Emptyable,
};

export type Decimal = import('./shared.js').Decimal;

export {StripeContext as StripeContextType};
export {StripeRawError};
export import ErrorType = _Error;
Expand Down
3 changes: 3 additions & 0 deletions src/stripe.esm.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,8 @@ export declare namespace Stripe {
Emptyable,
};

export type Decimal = import('./shared.js').Decimal;

export {StripeContext as StripeContextType};
export {StripeRawError};
export import ErrorType = _Error;
Expand All @@ -2461,4 +2463,5 @@ export declare namespace Stripe {

Stripe.initialize(new NodePlatformFunctions());

export {Decimal} from './shared.js';
Comment on lines 2456 to +2466
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

The new Stripe.Decimal namespace type and the new named export Decimal are both type-surface changes; consider adding/adjusting TypeScript compile-time tests to cover the intended usage (e.g., const d: Stripe.Decimal = Stripe.Decimal.from('1.0') and import type {Decimal} from 'stripe') so this doesn’t regress again.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — added const d: Stripe.Decimal = Stripe.Decimal.from('1.0') to both testProjects/types and mjs-ts, plus import type { Decimal } from 'stripe' in mjs-ts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really want to directly export Decimal class? Or should it live under Stripe namespace like the rest of the exported clases?

export default Stripe;
8 changes: 6 additions & 2 deletions testProjects/mjs-ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DefaultStripe, {Stripe} from 'stripe';
import DefaultStripe, {Stripe, type Decimal} from 'stripe';

const stripe = new Stripe(process.argv[2], {
// if we specify a version, then our smoke tests fail every time there's a new API version being prepped
Expand Down Expand Up @@ -48,4 +48,8 @@ exampleFunction({
payment_method: 'pm_card_visa',
});

Stripe.Decimal.from('1.0');
// Verify Stripe.Decimal works as both a runtime call and a type annotation.
const decimalInstance: Stripe.Decimal = Stripe.Decimal.from('1.0');
// Verify named type import works: import type { Decimal } from 'stripe'
const decimalViaNamedImport: Decimal = Stripe.Decimal.from('2.0');
console.log('Decimal:', decimalInstance.toString(), decimalViaNamedImport.toString());
3 changes: 2 additions & 1 deletion testProjects/types/typescriptTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,5 @@ async (): Promise<void> => {
let g: Stripe.V2.Core.Event;
}

Stripe.Decimal.from('1.0');
// Verify Stripe.Decimal works as both a runtime call and a type annotation.
const decimalInstance: Stripe.Decimal = Stripe.Decimal.from('1.0');
Loading