TypeScript types allow mails with missing bodies #978
Labels
difficulty: easy
fix is easy in difficulty
status: work in progress
Twilio or the community is in the process of implementing
type: bug
bug in the library
Issue Summary
Each SendGrid mail requires either a
text
key or anhtml
key. If neither is present, the server will reject the mail.The SendGrid TypeScript types'
MailData
type is the type passed tosendgrid.send
. It contain this:This is wrong, because it means that both
text
andhtml
are allowed to be absent. If you send such a request to the server, it will always be rejected with HTTP 400 Bad Request.Steps to Reproduce
sendgrid/mail
NPM package.sendgrid.send({from, to, subject})
(with notext
orhtml
provided).This is a bug in the types: they allow me to do something that's (1) invalid, and (2) statically preventable in TypeScript's type system. Our user feedback form was down in production for 24 hours because of this bug.
Technical details:
This can be fixed by doing something like:
With that change, the user can no longer call
sendgrid.send
without providing at least one type of body. (There are probably more types of bodies that I don't know about, and which would need to be considered in the union as well. I assume that's what thecontent
key is, for example. But I only know a relatively small part of SendGrid's API.)The text was updated successfully, but these errors were encountered: