Type error when sending mail with a template · Issue #1056 · sendgrid/sendgrid-nodejs · GitHub
Skip to content

Type error when sending mail with a template #1056

Description

@ogrodnek

Issue Summary

#1041 which requires email content to be present breaks sending email with a template.

Steps to Reproduce

Code Snippet

sendgrid.send({
  from: "from@example.com",
  to: "to@example.com",
  templateId: "d-d123abcd",
});

Exception/Log

error TS2769: No overload matches this call.
  Overload 1 of 2, '(data: MailDataRequired, isMultiple?: boolean | undefined, cb?: ((err: Error | ResponseError, result: [Response, {}]) => void) | undefined): Promise<...>', gave the following error.
    Argument of type '{ from: string; to: string; templateId: string; dynamicTemplateData: { secretLoginCode: string; signInLink: string; }; }' is not assignable to parameter of type 'MailDataRequired'.
      Type '{ from: string; to: string; templateId: string; dynamicTemplateData: { secretLoginCode: string; signInLink: string; }; }' is not assignable to type 'MailData & { content: MailContent[] & { 0: MailContent; }; }'.
        Property 'content' is missing in type '{ from: string; to: string; templateId: string; dynamicTemplateData: { secretLoginCode: string; signInLink: string; }; }' but required in type '{ content: MailContent[] & { 0: MailContent; }; }'.
  Overload 2 of 2, '(data: MailDataRequired[], isMultiple?: boolean | undefined, cb?: ((err: Error | ResponseError, result: [Response, {}]) => void) | undefined): Promise<...>', gave the following error.
    Argument of type '{ from: string; to: string; templateId: string; dynamicTemplateData: { secretLoginCode: string; signInLink: string; }; }' is not assignable to parameter of type 'MailDataRequired[]'.
      Object literal may only specify known properties, and 'from' does not exist in type 'MailDataRequired[]'.

 46     sendgrid
        ~~~~~~~~
 47       .send({
    ~~~~~~~~~~~~~
... 
 54         },
    ~~~~~~~~~~
 55       })
    ~~~~~~~~

  src/create-auth-challenge/node_modules/@sendgrid/mail/src/mail.d.ts:6:43
    6   { text: string } | { html: string } | { content: MailContent[] & { 0: MailContent } });
                                                ~~~~~~~
    'content' is declared here.

Technical details:

  • sendgrid-nodejs version:
  • node version:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions