From 4edc81dcac8b5eebbcf011727826ecd58e7e4f00 Mon Sep 17 00:00:00 2001 From: Dave Brudner Date: Tue, 14 Apr 2020 15:38:35 -0500 Subject: [PATCH] Restructures types for DT We restructured the types to comply with structural expectations in DefinitelyTyped (https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43900) This is a follow up to https://github.com/recurly/recurly-js/pull/591 which exports types. All types are now defined in lib. The index.d.ts declaration file is only responsible for declaring recurly as a global variable and exporting types. --- test/types/paypal.ts | 5 ++++ types/emitter.ts | 8 ------ types/index.d.ts | 38 +++++++++++++------------ types/{ => lib}/3d-secure.ts | 0 types/{ => lib}/address.ts | 0 types/{ => lib}/adyen.ts | 0 types/{ => lib}/apple-pay.ts | 0 types/{ => lib}/bank-account.ts | 0 types/{ => lib}/configure.ts | 0 types/{ => lib}/elements.ts | 0 types/lib/emitter.ts | 10 +++++++ types/{ => lib}/error.ts | 0 types/{ => lib}/gift-card.ts | 2 +- types/{ => lib}/paypal.ts | 8 +++++- types/{ => lib}/pricing/checkout.ts | 2 +- types/{ => lib}/pricing/index.ts | 0 types/{ => lib}/pricing/promise.ts | 0 types/{ => lib}/pricing/subscription.ts | 0 types/{ => lib}/recurly.ts | 12 -------- types/{ => lib}/token.ts | 0 types/{ => lib}/validate.ts | 0 21 files changed, 44 insertions(+), 41 deletions(-) delete mode 100644 types/emitter.ts rename types/{ => lib}/3d-secure.ts (100%) rename types/{ => lib}/address.ts (100%) rename types/{ => lib}/adyen.ts (100%) rename types/{ => lib}/apple-pay.ts (100%) rename types/{ => lib}/bank-account.ts (100%) rename types/{ => lib}/configure.ts (100%) rename types/{ => lib}/elements.ts (100%) create mode 100644 types/lib/emitter.ts rename types/{ => lib}/error.ts (100%) rename types/{ => lib}/gift-card.ts (87%) rename types/{ => lib}/paypal.ts (78%) rename types/{ => lib}/pricing/checkout.ts (95%) rename types/{ => lib}/pricing/index.ts (100%) rename types/{ => lib}/pricing/promise.ts (100%) rename types/{ => lib}/pricing/subscription.ts (100%) rename types/{ => lib}/recurly.ts (84%) rename types/{ => lib}/token.ts (100%) rename types/{ => lib}/validate.ts (100%) diff --git a/test/types/paypal.ts b/test/types/paypal.ts index 65b4a9e4b..f699eff97 100644 --- a/test/types/paypal.ts +++ b/test/types/paypal.ts @@ -22,5 +22,10 @@ export default function paypal() { paypal.on('fake-event', () => {}); paypal.start(); + paypal.start({ + options: { + description: "description" + } + }); paypal.destroy(); } diff --git a/types/emitter.ts b/types/emitter.ts deleted file mode 100644 index cf72a9e4b..000000000 --- a/types/emitter.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface Emitter { - on(event: Event, listener: Function): Emitter; - once(event: Event, listener: Function): Emitter; - off(event?: Event, listener?: Function): Emitter; - emit(event: Event, ...args: any[]): Emitter; - listeners(event: Event): Function[]; - hasListeners(event: Event): boolean; -} diff --git a/types/index.d.ts b/types/index.d.ts index caef773ea..346f63fc7 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -5,28 +5,30 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.1 -import { Recurly } from './recurly'; +import { Recurly } from './lib/recurly'; declare global { interface Window { recurly: Recurly; } + + const recurly: Recurly; } -export * from './pricing/checkout'; -export * from './pricing/promise'; -export * from './pricing/subscription'; -export * from './pricing'; -export * from './3d-secure'; -export * from './address'; -export * from './adyen'; -export * from './apple-pay'; -export * from './bank-account'; -export * from './configure'; -export * from './elements'; -export * from './error'; -export * from './gift-card'; -export * from './paypal'; -export * from './recurly'; -export * from './token'; -export * from './validate'; +export * from './lib/pricing/checkout'; +export * from './lib/pricing/promise'; +export * from './lib/pricing/subscription'; +export * from './lib/pricing/index'; +export * from './lib/3d-secure'; +export * from './lib/address'; +export * from './lib/adyen'; +export * from './lib/apple-pay'; +export * from './lib/bank-account'; +export * from './lib/configure'; +export * from './lib/elements'; +export * from './lib/error'; +export * from './lib/gift-card'; +export * from './lib/paypal'; +export * from './lib/recurly'; +export * from './lib/token'; +export * from './lib/validate'; diff --git a/types/3d-secure.ts b/types/lib/3d-secure.ts similarity index 100% rename from types/3d-secure.ts rename to types/lib/3d-secure.ts diff --git a/types/address.ts b/types/lib/address.ts similarity index 100% rename from types/address.ts rename to types/lib/address.ts diff --git a/types/adyen.ts b/types/lib/adyen.ts similarity index 100% rename from types/adyen.ts rename to types/lib/adyen.ts diff --git a/types/apple-pay.ts b/types/lib/apple-pay.ts similarity index 100% rename from types/apple-pay.ts rename to types/lib/apple-pay.ts diff --git a/types/bank-account.ts b/types/lib/bank-account.ts similarity index 100% rename from types/bank-account.ts rename to types/lib/bank-account.ts diff --git a/types/configure.ts b/types/lib/configure.ts similarity index 100% rename from types/configure.ts rename to types/lib/configure.ts diff --git a/types/elements.ts b/types/lib/elements.ts similarity index 100% rename from types/elements.ts rename to types/lib/elements.ts diff --git a/types/lib/emitter.ts b/types/lib/emitter.ts new file mode 100644 index 000000000..11ad8b354 --- /dev/null +++ b/types/lib/emitter.ts @@ -0,0 +1,10 @@ +type Listener = (...args: any[]) => void; + +export interface Emitter { + on(event: Event, listener: Listener): Emitter; + once(event: Event, listener: Listener): Emitter; + off(event?: Event, listener?: Listener): Emitter; + emit(event: Event, ...args: any[]): Emitter; + listeners(event: Event): Listener[]; + hasListeners(event: Event): boolean; +} diff --git a/types/error.ts b/types/lib/error.ts similarity index 100% rename from types/error.ts rename to types/lib/error.ts diff --git a/types/gift-card.ts b/types/lib/gift-card.ts similarity index 87% rename from types/gift-card.ts rename to types/lib/gift-card.ts index db33a2b92..61138af46 100644 --- a/types/gift-card.ts +++ b/types/lib/gift-card.ts @@ -1,4 +1,4 @@ -import { RecurlyError } from './'; +import { RecurlyError } from './error'; export type GiftCardOptions = { code: string; diff --git a/types/paypal.ts b/types/lib/paypal.ts similarity index 78% rename from types/paypal.ts rename to types/lib/paypal.ts index 7c4617390..39d2c5f3e 100644 --- a/types/paypal.ts +++ b/types/lib/paypal.ts @@ -17,8 +17,14 @@ export type PayPalConfig = BraintreeConfig | DirectConfig; export type PayPalEvent = 'error' | 'token'; +export type PayPalStartOptions = { + options: { + description: string; + } +}; + export interface PayPalInstance extends Emitter { - start: VoidFunction; + start: (payPalStartOptions?: PayPalStartOptions) => void; token: TokenHandler; destroy: VoidFunction; } diff --git a/types/pricing/checkout.ts b/types/lib/pricing/checkout.ts similarity index 95% rename from types/pricing/checkout.ts rename to types/lib/pricing/checkout.ts index b4275f350..9d7c4d969 100644 --- a/types/pricing/checkout.ts +++ b/types/lib/pricing/checkout.ts @@ -76,7 +76,7 @@ export interface CheckoutPricingMethods { giftCard: (giftcard: string) => CheckoutPricingPromise; shippingAddress: (address: Address) => CheckoutPricingPromise; tax: (tax: Tax) => CheckoutPricingPromise; - subscription: (subscriptionPricing: SubscriptionPricingState | void) => CheckoutPricingPromise; + subscription: (subscriptionPricing: SubscriptionPricingState) => CheckoutPricingPromise; } export interface CheckoutPricingInstance extends CheckoutPricingMethods, PricingInstance { diff --git a/types/pricing/index.ts b/types/lib/pricing/index.ts similarity index 100% rename from types/pricing/index.ts rename to types/lib/pricing/index.ts diff --git a/types/pricing/promise.ts b/types/lib/pricing/promise.ts similarity index 100% rename from types/pricing/promise.ts rename to types/lib/pricing/promise.ts diff --git a/types/pricing/subscription.ts b/types/lib/pricing/subscription.ts similarity index 100% rename from types/pricing/subscription.ts rename to types/lib/pricing/subscription.ts diff --git a/types/recurly.ts b/types/lib/recurly.ts similarity index 84% rename from types/recurly.ts rename to types/lib/recurly.ts index 3f6ca6ce3..faaf97dfa 100644 --- a/types/recurly.ts +++ b/types/lib/recurly.ts @@ -26,15 +26,3 @@ export interface Recurly extends Emitter { token: Token; validate: Validate; } - -declare global { - interface Window { - recurly: Recurly; - } - - namespace Recurly { - type recurly = Recurly; - } - - const recurly: Recurly; -} diff --git a/types/token.ts b/types/lib/token.ts similarity index 100% rename from types/token.ts rename to types/lib/token.ts diff --git a/types/validate.ts b/types/lib/validate.ts similarity index 100% rename from types/validate.ts rename to types/lib/validate.ts