-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose MandateDetailsCreditCard type #356
Comments
@janpaepke I think it could hurt, as @jp1987 Could you elaborate on how you are currently using |
@Pimm in a custom mapper: export const mapCreditCardMandates = (client: IClient, mandate: Mandate) => {
const mandateDetailsCreditCard = mandate.details as MandateDetailsCreditCard;
return {
active: client.mollieActiveMandateId === mandate.id,
cardHolder: mandateDetailsCreditCard.cardHolder,
cardLabel: mandateDetailsCreditCard.cardLabel,
cardNumber: mandateDetailsCreditCard.cardNumber,
mandateId: mandate.id,
status: mandate.status,
};
};
|
Thanks for elaborating, Jesper. I think this warrants a conversation about the types we (don't) want to expose. A discriminated union might actually help in this specific case: if (mandate.method == 'creditcard') {
mandate.details.cardHolder // ← guaranteed to exist inside this if-block.
} |
Not only would this help, but it would make the code more reliable. export const mapCreditCardMandates = (client: IClient, mandate: Mandate) => {
if (mandate.method !== 'creditcard') {
throw new Error(`Unexpected mandate method ${mandate.method}.`);
}
return {
active: client.mollieActiveMandateId === mandate.id,
cardHolder: mandateDetailsCreditCard.cardHolder,
cardLabel: mandateDetailsCreditCard.cardLabel,
cardNumber: mandateDetailsCreditCard.cardNumber,
mandateId: mandate.id,
status: mandate.status,
};
}; This does NOT work currently, as the sdk does not expose this as a discriminated union. @Pimm do you want to have this conversation here or open up a separate issue for this? |
When using TypeScript, I can't seem to import MandateDetailsCreditCard as a type through
@mollie/api-client
, but only like so:import type { MandateDetailsCreditCard } from '@mollie/api-client/dist/types/src/data/customers/mandates/data';
The text was updated successfully, but these errors were encountered: