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

TypeScript: 'template' does not exist in type 'Options' #79

Open
alusev opened this issue Jun 5, 2019 · 7 comments
Open

TypeScript: 'template' does not exist in type 'Options' #79

alusev opened this issue Jun 5, 2019 · 7 comments
Labels

Comments

@alusev
Copy link

alusev commented Jun 5, 2019

I cannot specify a template. I have the following code:

import nodemailer from "nodemailer";
import mg from "nodemailer-mailgun-transport";
import dotenv from "dotenv";
import Mail from "nodemailer/lib/mailer";
import pug from "pug";

dotenv.config();

const {
    MG_API_KEY = "",
    MG_DOMAIN = "",
    MG_FROM_EMAIL = "",
    MG_FROM_NAME = ""
} = process.env;

const auth = {
    auth: {
        api_key: MG_API_KEY,
        domain: MG_DOMAIN
    },
};

const nodemailerMailgun = nodemailer.createTransport(mg(auth));

export interface IMailAddress {
    name?: string;
    address: string;
}

export const sendMail = (to: Mail.Address, subject: string, templateName: string, context: any = {}) => {
    return nodemailerMailgun.sendMail({
        from: { name: MG_FROM_NAME, address: MG_FROM_EMAIL },
        to, subject,
        template: {
            name: templateName,
            engine: 'pug',
            context: context
        }
    });
}

This is the error:
Object literal may only specify known properties, and 'template' does not exist in type 'Options'.

@alusev alusev changed the title 'template' does not exist in type 'Options' TypeScript: 'template' does not exist in type 'Options' Jun 5, 2019
@JaquelinaG
Copy link

Any news on this error? I have the same problem!

@amine-louni
Copy link

Any updates ?

@josethz00
Copy link

any updates?

@josethz00
Copy link

josethz00 commented Mar 14, 2022

As we don't have an official solution yet, I just downgraded my types/nodemailer version to 6.1.0 and then the problem was solved. I also noticed that this bug is present since the 6.2.2 version.

@rohanrajpal
Copy link

Facing the same issue :/

@mechadragon01
Copy link

Any updates?

@enyineer
Copy link

You could just extend the Options type like this:

import { Options } from "nodemailer/lib/mailer";

type ExtendedOptions = Options & { template: string, context: Record<string, unknown> };

const options: ExtendedOptions = {
  from: '"enyineer@github" <[email protected]>',
  to: '[email protected]',
  template: 'myTemplateName',
  context: {
    foo: 'bar',
  },
};

await transport.sendMail(options);

Fixes the TypeScript complaint until the types are corrected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants