Skip to content

Mismatch between Mailtrap template platform and Node.js SDK template variable types #84

@zcamcal

Description

@zcamcal

Hi!

Problem.

I'm using mailtrap nodejs library also in my Mailtrap account I have a template with a json attributes that has arrays also inners objects, but when I try to use the auto generated json that offers Mailtrap template platform, I cant because the type is a record only for [string | number | boolean], I'm talking about the template_variables?: TemplateVariables, for now I just use a variable to make the json as any and then pass to the send function and it works.

But I'm wondering if there is a reason for this, also I check the code where is it used but cant find something that dont allow use some record that allows the use of arrays or objects, maybe is about the flatten function but I'm not sure.

To Reproduce

Steps to reproduce the behavior:
1- install nodejs
2- add mailtrap library
3- add nodemailer
4- add ts types developers libs
5- create a json with some array or object like this example and save it to a const typed as Mail from 'import { Mail, MailtrapClient } from "mailtrap"'

{
  "x": {
      "y": "this will fail"
  }
}

Proposal

Use something like, I dont know if the cyclic references will be a problem but besides that it will helps to take more benefits from mailtrap template system.

export type TemplateValue =
  | string
  | number
  | boolean
  | TemplateValue[]
  | { [key: string]: TemplateValue };

export type TemplateVariables = Record<string, TemplateValue>;

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions