The type definition for PersonalizationData
contains a field called dynamicTemplateData
. However, the SendGrid API expects a field called dynamic_template_data
. As a result, TypeScript users currently have to cast the MailData
object to type any
if they want to use the sgMail.send()
method without a compiler error:
sgMail.send({
personalizations: [
{
to: "[email protected]",
dynamic_template_data: {
field1: "value1",
field2: "value2"
}
}
],
from: 'noreply@email',
templateId: "xxxxxxxx"
} as any);
So, either the field name in the PersonalizationData
type should be changed to match with what the API expects, or a mapping should occur from dynamicTemplateData
=> dynamic_template_data
.
Thank you @egges!
This is a great catch and I've added this to our backlog for an update or perhaps we will get a PR.
With Best Regards,
Elmer
@egges similar issue I had.
For those interested, this is how I fixed the problem
https://github.com/sendgrid/sendgrid-nodejs/pull/716#issuecomment-472932577
same question to @thinkingserious, why as this not been deployed yet? PR is ready and is a big problem for us typescripters 😄
As best as I can tell, the typescript definitions are correct and this is not an issue. When the personalizations object is serialized to JSON, keys are recursively converted to snake_case
including the dynamicTemplateData
key (source, note that the exclusions list are the keys that are not to be recursively converted, just the top-level key itself).
Please re-open if I'm wrong and missing something. Just looking at the latest version of the code.
Most helpful comment
@egges similar issue I had.
For those interested, this is how I fixed the problem
https://github.com/sendgrid/sendgrid-nodejs/pull/716#issuecomment-472932577
same question to @thinkingserious, why as this not been deployed yet? PR is ready and is a big problem for us typescripters 😄