I'm running into a problem with Typescript because it doesn't let me build an email without a content field. Is the MailDataRequired
correct?
I never used to send content with my emails. Only substitutions. The content / templates live on your servers.
export type MailDataRequired = MailData & (
{ text: string } | { html: string } | { templateId: string } | { content: MailContent[] & { 0: MailContent } });
# paste exception/log here
BTW: 6.5.0 doesn't seem to have this weird { 0: MailContent }
requirement, but still content is required.
watching this one too. updated my package and now not sure about this
Considering this a duplicate of https://github.com/sendgrid/sendgrid-nodejs/issues/1056, unless I'm mistaken.
text
, html
, or content
. It was later pointed out that templateId
by itself should also be allowed. This was fixed as part #1053 but has yet to be released.@childish-sambino this is still an issue on 6.5.4
the type is defined like this:
type MailDataRequired = MailData & (
{ text: string } | { html: string } | { content: MailContent[] & { 0: MailContent } });
That is making content
a required property, is there a reason for that when MailData
defines it as a conditional property? I fixed it by passing:
{...mailData, content: undefined}
1041 introduced in the 6.5.4 release required one of
text
,html
, orcontent
.
@rodrigomf24 Does mailData
not have one of those?
@childish-sambino no just a templateId
and dynamicTemplateData
@rodrigomf24
It was later pointed out that templateId by itself should also be allowed. This was fixed as part #1053 but has yet to be released.
Is this fix released?
I just got version 7.0.0 and I still see this error
TSError: ⨯ Unable to compile TypeScript:
src/email-templates/verification-email-template.ts(15,25): error TS2769: No overload matches this call.
Overload 1 of 2, '(data: MailDataRequired, isMultiple?: boolean | undefined, cb?: ((err: Error | ResponseError, result: [ClientResponse, {}]) => void) | undefined): Promise<...>', gave the following error.
If this has changed in 7.0.0, where is latest documentation for the send api please? Can't find much here. @childish-sambino
Thanks.
Yes, this was released in 6.5.5
@childish-sambino What do you think about exporting MailDataRequired
from the @sendgrid/mail
package as well?
@isaachinman I've no issue with that. If you want to submit a PR I can review it.
@childish-sambino I had a look around, and am unfamiliar with the module approach of export =
being taken here. I'm not clear on how this can be expanded without introducing breaking changes.
Happy to help if you can point me in the right direction.
Think this line can just be updated: https://github.com/sendgrid/sendgrid-nodejs/blob/master/packages/mail/src/mail.d.ts#L37
Like this maybe:
declare const mail: MailService & { MailService: typeof MailService, MailDataRequired: typeof MailDataRequired };
No, that won't work as MailDataRequired
is already a type. The use of declare const
makes things slightly complicated.
Then just , MailDataRequired: MailDataRequired };
?
No, what I am saying is that literally adds a MailDataRequired
attribute to the default export. If you tried out your latest suggestion, you'd get a refers to a value, but is being used as a type
error.
I haven't seen any other packages managing types with this sort of module approach, so I can't really offer you any suggestions. You need a way of supporting named exports.
Normally I'd expect to see something like this:
export default mail
export { MailDataRequired }
@isaachinman Think this (hack) should fix it: https://github.com/sendgrid/sendgrid-nodejs/pull/1102
Most helpful comment
BTW: 6.5.0 doesn't seem to have this weird
{ 0: MailContent }
requirement, but still content is required.