Skip to content
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

export type MailDataRequired generate errors in arguments (Typescript) #1166

Open
jaun-rg opened this issue Jul 21, 2020 · 9 comments
Open
Labels
status: help wanted requesting help from the community type: bug bug in the library

Comments

@jaun-rg
Copy link

jaun-rg commented Jul 21, 2020

When use send function in typescript, this generate a error Argument for types (specifically with content resolution)

Issue Summary

Steps to Reproduce

Code Snippet

import MailService from '@sendgrid/mail';

...

const emailOpts = {
        to: [<your email here>],
        from : <verified email in sendrid account for send emails>,
        subject: 'Sending with Twilio SendGrid is Fun',
        text: 'and easy to do anywhere, even with Node.js',
        html: '<strong>and easy to do anywhere, even with Node.js</strong>'
      }
serviceResp = await MailService.send(emailOpts);
...

Exception/Log

Argument of type '(MailData & { text: string; }) | (MailData & { html: string; }) | (MailData & { templateId: string; }) | (MailData & { content: MailContent[] & { ...; }; })' is not assignable to parameter of type 'MailDataRequired'.

      Property 'content' is missing in type 'EmailInput' but required in type '{ content: MailContent[] & { 0: MailContent; }; }'.

Additional log in debug:
Screen Shot 2020-07-20 at 20 50 09

Technical details:

  • sendgrid-nodejs version: "^7.2.1"
  • node version: 14.4.0
@eshanholtz
Copy link
Contributor

Hi @jaun-rg

I was able to reproduce this bug. This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

@eshanholtz eshanholtz added status: help wanted requesting help from the community type: bug bug in the library labels Jul 24, 2020
@thibaultadet
Copy link

Hello !
I have the same issue.
Do you have a temporary solution while waiting for a fix ?

@FMathemera
Copy link

Hi,
Has this issue been resolved yet, seems like this thread has become stale.

@inorganik
Copy link

Hi, is there any progress on this? Even the type definitions file mail.d.ts has broken imports in it, so I can't see type definitions for what is required for me to send mail.

I tried to install @types/sendgrid and it installed an empty package:

This is a stub types definition for sendgrid (https://github.com/sendgrid/sendgrid-nodejs).
sendgrid provides its own type definitions, so you don't need @types/sendgrid installed!

I'm unable to import any types from the current package.

@JonCognioDigital
Copy link

Same problem here. I cannot work out how to get typings for the "msg" object in sgMail.send(msg). I've looked absolutely everywhere and the solution posted elsewhere which says to use

import * as SendGrid from '@sendgrid/mail'
const msg: typeof SendGrid.MailService = {...}

soesn't work because the Sendgrid object doesn't export a member called MailService.

@ilionic
Copy link

ilionic commented Feb 18, 2021

@jon64digital try:

import { MailDataRequired } from '@sendgrid/helpers/classes/mail';

const msg: MailDataRequired = {...}

Also, fwiw:

import * as MailService from '@sendgrid/mail';

MailService.setApiKey('...');
...
const response = await MailService.send(msg);

@syJSdev
Copy link

syJSdev commented Apr 14, 2021

Hi,

I have an issue using the MailDataRequired type.
I can't use the second option (mentioned in the below document) with typescript.
https://github.com/sendgrid/sendgrid-nodejs/blob/main/docs/use-cases/transactional-templates.md#prevent-escaping-characters.

@ps2goat
Copy link

ps2goat commented May 6, 2021

I had the same problem, where a MailDataRequired is required by the send function. I'm working with a template id and template data, so I don't need the content node. I used the type MailData and I cast it to <any> as a temporary workaround.

// need @sendgrid/mail and @sendgrid/helpers installed
import sendgrid from '@sendgrid/mail';
import { MailData } from '@sendgrid/helpers/classes/mail';

// this is simplified, but there is no `content` node.
const payload: MailData = this.getPayload();
await sendgrid.send(<any>payload);

The function should take a MailData (MailDataRequired fits this interface), OR possibly split functionality across multiple methods-- one for send with a template and one for send with the content provided.

@Tokenyet
Copy link

Tokenyet commented Oct 18, 2021

This annoying bug keeps going to Typescript coders 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

10 participants