Search code examples
node.jstypescripttypesnodemailer

What is the return type of nodemailer's transporter.sendMail()?


I got this piece of code:

import nodemailer from "nodemailer";

const transporter = nodemailer.createTransport({
  host: "smtp...",
  port: 587,
  secure: false,
  requireTLS: true,
  auth: {...}
});

const result = await transporter.sendMail({
  from: "XXX",
  to: "YYY",
  subject: "ZZZ",
  text: "WWW"
});

Typescript is currently evaluation the result as any.

enter image description here

Is this correct?

I have also installed @types/nodemailer. This is the type definition contained in it:

enter image description here

Even if I try to type it as SentMessageInfo directly, I also get any:

import { SentMessageInfo } from "nodemailer";

const result: SentMessageInfo = await transporter.sendMail({...});

enter image description here

Am I doing something wrong? Or there is really no type definition for that?

The type for transporter seems to be correct (the type is Mail).

enter image description here


Solution

  • The type is correct, SentMessageInfo is simply an alias for any:

    export type SentMessageInfo = any;