Skip to content

fix: Corrected lack of optional parameters for creating multiple mailing list members#444

Open
leovietro wants to merge 1 commit into
mailgun:masterfrom
leovietro:master
Open

fix: Corrected lack of optional parameters for creating multiple mailing list members#444
leovietro wants to merge 1 commit into
mailgun:masterfrom
leovietro:master

Conversation

@leovietro
Copy link
Copy Markdown

Hello,

I encountered an issue while integrating this SDK into our project. Our mailing lists only store email addresses and ignore the other optional parameters defined in the CreateUpdateMailListMembers type:

type CreateUpdateMailListMembers = {
    address: string;
    name?: string;
    vars?: string;
    subscribed?: 'yes' | 'no' | boolean;
    upsert?: 'yes' | 'no';
}

However, the IMailListsMembers.createMembers method requires the members parameter to use the MailListMember type, which mandates all properties:

type MailListMember = {
    address: string;
    name: string;
    subscribed: boolean,
    vars: {
        [key: string]: unknown
    };
}

Our temporary workaround was to cast the parameter to any, but we don't like that :P

return await client.lists.members.createMembers(listAddress, {
      members: members.map(
        (address) =>
          ({
            address,
            // This cast was made because of an error on the Mailgun SDK typing that makes some MailListMember optional properties obligatory.
          }) as any,
      ),
      upsert: 'yes',
    });

To resolve this cleanly, I created a new type for IMailListsMembers.createMembers that makes these properties optional. Although I considered using the existing CreateUpdateMailListMembers with Omit<> to remove the upsert field, a new type looks clearer and simpler for casting:

export type CreateMultipleMailListMembers = Array<{
    address: string;
    name?: string;
    vars?: string;
    subscribed?: boolean;
}>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant