diff --git a/src/shared.ts b/src/shared.ts index 53e39b5..d330f5b 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -1,7 +1,8 @@ import { IStripeConnectInitParams, StripeConnectInstance, - ConnectElementTagName + ConnectElementTagName, + ConnectHTMLElementRecord } from "../types"; export type LoadConnectAndInitialize = ( @@ -119,14 +120,14 @@ export const initStripeConnect = ( create: tagName => { let htmlName = componentNameMapping[tagName]; if (!htmlName) { - htmlName = tagName as ConnectElementHTMLName; + htmlName = (tagName as unknown) as ConnectElementHTMLName; } const element = document.createElement(htmlName); stripeConnectInstance.then(instance => { (element as any).setConnector((instance as any).connect); }); - return element; + return element as ConnectHTMLElementRecord[typeof tagName]; }, update: updateOptions => { stripeConnectInstance.then(instance => { diff --git a/types/shared.d.ts b/types/shared.d.ts index 7597fbd..7309809 100644 --- a/types/shared.d.ts +++ b/types/shared.d.ts @@ -354,13 +354,38 @@ export interface IStripeConnectInitParams { locale?: string; } +type ConnectHTMLElementRecordFallback = { + [key in string]: HTMLElement | null; +}; +type ConnectHTMLElementRecordBase = { + [tagName in ConnectElementTagName]: HTMLElement; +}; + +interface ConnectHTMLElementRecord + extends ConnectHTMLElementRecordBase, + ConnectHTMLElementRecordFallback { + "account-onboarding": HTMLElement & { + setFullTermsOfServiceUrl: (termOfServiceUrl: string | undefined) => void; + setRecipientTermsOfServiceUrl: ( + recipientTermsOfServiceUrl: string | undefined + ) => void; + setPrivacyPolicyUrl: (privacyPolicyUrl: string | undefined) => void; + setSkipTermsOfServiceCollection: ( + skipTermsOfServiceCollection: boolean | undefined + ) => void; + setOnExit: (listener: () => void) => void; + }; +} + export interface StripeConnectInstance { /** * Creates a Connect element. * @tagName Name of the Connect component to create. * @returns An HTML component corresponding to that connect component */ - create: (tagName: ConnectElementTagName) => HTMLElement; + create: ( + tagName: T + ) => ConnectHTMLElementRecord[T]; /** * Updates the Connect instance with new parameters.