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

Sendgrid with TypeScript > 4.4 #1344

Open
jvineveld opened this issue Feb 28, 2022 · 5 comments
Open

Sendgrid with TypeScript > 4.4 #1344

jvineveld opened this issue Feb 28, 2022 · 5 comments
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@jvineveld
Copy link

Issue Summary

Updating typescript broke sendgrid because of the class instance export
When trying to set API key by calling 'setApiKey', it will fail because 'this' is undefined.

The issue is the result of this change in TypeScript:
https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#more-compliant-indirect-calls-for-imported-functions

Steps to Reproduce

Install sendgrid on an typescript > 4.4 environment
try to use sendgrid to send a mail

Technical details:

  • sendgrid-nodejs version: 7.2.6
  • node version: 14.17.3
@childish-sambino childish-sambino added status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap labels Mar 9, 2022
@childish-sambino
Copy link
Contributor

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

@anttispitkanen
Copy link

Any update on this? Or potential mitigation? This is essentially blocking upgrading to TypeScript >=4.4 👀

@anttispitkanen
Copy link

Seems like I was able to work around this by importing and instantiating a MailService class and using the methods via that. So instead of

import { send, setApiKey  } from '@sendgrid/mail'

setApiKey(environment.sendgrid.apiKey)

// ...and usage...
await send(/* something *)

doing it like

import { MailDataRequired, MailService } from '@sendgrid/mail'

const SendGrid = new MailService()

SendGrid.setApiKey(environment.sendgrid.apiKey)

// ...and usage...
await SendGrid.send(/* something */)

but please feel free to let me know if there's something wrong with this approach. Seems to work for TypeScript versions older and newer than 4.4.x.

@anttispitkanen
Copy link

After some testing it indeed seems like my solution above works, so is this more a question of updating the documentation to reflect that as the correct way of doing things? 👀

@corbinu
Copy link

corbinu commented Mar 29, 2022

Just got bit by this and it seems a pretty breaking issue for it to simply be backlogged. @anttispitkanen Thank you for the workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

4 participants