Skip to content

Commit fe2f78c

Browse files
authored
handle shadowed namespaces (#2753)
* handle shadowed namespaces * add type test
1 parent 56a570f commit fe2f78c

6 files changed

Lines changed: 41 additions & 15 deletions

File tree

src/resources/Checkout/Sessions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import {StripeResource} from '../../StripeResource.js';
44
import {LineItem} from './../LineItems.js';
5-
import {Discount} from './../Discounts.js';
5+
import {Discount as _Discount} from './../Discounts.js';
66
import {Subscription} from './../Subscriptions.js';
77
import {Customer, DeletedCustomer} from './../Customers.js';
88
import {Invoice} from './../Invoices.js';
@@ -3519,7 +3519,7 @@ export namespace Checkout {
35193519
*
35203520
* Related guide: [Applying discounts to subscriptions](https://docs.stripe.com/billing/subscriptions/discounts)
35213521
*/
3522-
discount: Discount;
3522+
discount: _Discount;
35233523
}
35243524

35253525
export interface Tax {

src/resources/CreditNotes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import {StripeResource} from '../StripeResource.js';
44
import {CreditNoteLineItem} from './CreditNoteLineItems.js';
5-
import {Refund} from './Refunds.js';
5+
import {Refund as _Refund} from './Refunds.js';
66
import {Customer, DeletedCustomer} from './Customers.js';
77
import {CustomerBalanceTransaction} from './CustomerBalanceTransactions.js';
88
import {Invoice} from './Invoices.js';
@@ -593,7 +593,7 @@ export namespace CreditNote {
593593
/**
594594
* ID of the refund.
595595
*/
596-
refund: string | Refund;
596+
refund: string | _Refund;
597597

598598
/**
599599
* Type of the refund, one of `refund` or `payment_record_refund`.

src/resources/LineItems.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// File generated from our OpenAPI spec
22

3-
import {Discount} from './Discounts.js';
3+
import {Discount as _Discount} from './Discounts.js';
44
import {Price} from './Prices.js';
55
import {TaxRate} from './TaxRates.js';
66
import {Metadata} from '../shared.js';
@@ -94,7 +94,7 @@ export namespace LineItem {
9494
*
9595
* Related guide: [Applying discounts to subscriptions](https://docs.stripe.com/billing/subscriptions/discounts)
9696
*/
97-
discount: Discount;
97+
discount: _Discount;
9898
}
9999

100100
export interface Tax {

src/resources/Quotes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import {StripeResource} from '../StripeResource.js';
44
import {LineItem} from './LineItems.js';
5-
import {Discount} from './Discounts.js';
5+
import {Discount as _Discount} from './Discounts.js';
66
import {Application, DeletedApplication} from './Applications.js';
77
import {Customer, DeletedCustomer} from './Customers.js';
88
import {TaxRate} from './TaxRates.js';
@@ -1059,7 +1059,7 @@ export interface Quote {
10591059
/**
10601060
* The discounts applied to this quote.
10611061
*/
1062-
discounts: Array<string | Discount>;
1062+
discounts: Array<string | _Discount>;
10631063

10641064
/**
10651065
* The date on which the quote will be canceled if in `open` or `draft` status. Measured in seconds since the Unix epoch.
@@ -1393,7 +1393,7 @@ export namespace Quote {
13931393
*
13941394
* Related guide: [Applying discounts to subscriptions](https://docs.stripe.com/billing/subscriptions/discounts)
13951395
*/
1396-
discount: Discount;
1396+
discount: _Discount;
13971397
}
13981398

13991399
export interface Tax {
@@ -1488,7 +1488,7 @@ export namespace Quote {
14881488
*
14891489
* Related guide: [Applying discounts to subscriptions](https://docs.stripe.com/billing/subscriptions/discounts)
14901490
*/
1491-
discount: Discount;
1491+
discount: _Discount;
14921492
}
14931493

14941494
export interface Tax {
@@ -1608,7 +1608,7 @@ export namespace Quote {
16081608
*
16091609
* Related guide: [Applying discounts to subscriptions](https://docs.stripe.com/billing/subscriptions/discounts)
16101610
*/
1611-
discount: Discount;
1611+
discount: _Discount;
16121612
}
16131613

16141614
export interface Tax {

src/resources/SubscriptionSchedules.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// File generated from our OpenAPI spec
22

33
import {StripeResource} from '../StripeResource.js';
4-
import {Discount} from './Discounts.js';
4+
import {Discount as _Discount} from './Discounts.js';
55
import {Application, DeletedApplication} from './Applications.js';
66
import {Customer, DeletedCustomer} from './Customers.js';
77
import {Subscription} from './Subscriptions.js';
@@ -674,7 +674,7 @@ export namespace SubscriptionSchedule {
674674
/**
675675
* ID of an existing discount on the object (or one of its ancestors) to reuse.
676676
*/
677-
discount: string | Discount | null;
677+
discount: string | _Discount | null;
678678

679679
/**
680680
* ID of the promotion code to create a new discount for.
@@ -763,7 +763,7 @@ export namespace SubscriptionSchedule {
763763
/**
764764
* ID of an existing discount on the object (or one of its ancestors) to reuse.
765765
*/
766-
discount: string | Discount | null;
766+
discount: string | _Discount | null;
767767

768768
/**
769769
* ID of the promotion code to create a new discount for.
@@ -868,7 +868,7 @@ export namespace SubscriptionSchedule {
868868
/**
869869
* ID of an existing discount on the object (or one of its ancestors) to reuse.
870870
*/
871-
discount: string | Discount | null;
871+
discount: string | _Discount | null;
872872

873873
/**
874874
* ID of the promotion code to create a new discount for.

testProjects/types/typescriptTest.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,32 @@ event = stripe.webhooks.constructEvent(
389389
'secret'
390390
);
391391

392+
// Verify that nested types with names matching imported types resolve correctly.
393+
// e.g. Checkout.Session.TotalDetails.Breakdown.Discount.discount should be
394+
// Stripe.Discount, not a self-referential Breakdown.Discount. (DEVSDK-3139)
395+
{
396+
const session = {} as Stripe.Checkout.Session;
397+
for (const item of session.total_details?.breakdown?.discounts ?? []) {
398+
const discount: Stripe.Discount = item.discount as Stripe.Discount;
399+
const promoCode: string | Stripe.PromotionCode | null =
400+
discount.promotion_code;
401+
const customer: string | Stripe.Customer | Stripe.DeletedCustomer | null =
402+
discount.customer;
403+
const start: number = discount.start;
404+
}
405+
406+
const schedule = {} as Stripe.SubscriptionSchedule;
407+
for (const phase of schedule.phases) {
408+
for (const d of phase.discounts) {
409+
if (typeof d.discount !== 'string' && d.discount) {
410+
const promoCode: string | Stripe.PromotionCode | null =
411+
d.discount.promotion_code;
412+
const start: number = d.discount.start;
413+
}
414+
}
415+
}
416+
}
417+
392418
const v2AccountCreateParamConfiguration: Stripe.V2.Core.AccountCreateParams.Configuration = {};
393419
const checkoutSessionParam: Stripe.Checkout.SessionCreateParams = {};
394420
const v2EventListParams: Stripe.V2.Core.EventListParams = {};

0 commit comments

Comments
 (0)