-
Notifications
You must be signed in to change notification settings - Fork 778
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
Cannot import type definitions from @sendgrid/mail
#674
Comments
Any ideas? |
Hi @killtheliterate, Can you let me know if this works for you? import * as SendGrid from "@sendgrid/mail";
SendGrid.setApiKey("blahblah")
interface Foo {
mail: typeof SendGrid.MailService
}
const foo: Foo = {
mail: SendGrid
}
export = foo It appears to work fine locally for me, the big difference being the use of the |
@spartan563 that does the trick, thank you! Is there a link you could toss me that explains why the |
Great! The reason why the original version ( Take the following example: const X = {
x: String
}
interface Y {
y: X.x
} Looking at that, you'd probably expect it not to work since you're trying to constrain a type based on the value of a const X = {
x: String
}
interface Y {
y: typeof X.x // String
} Exactly the same thing is at play here due to the gymnastics we had to perform to represent the library's interface in TypeScript. Unfortunately libraries that make use of the old NodeJS I hope that explains what's going on and why, but please feel free to ask if you've got any other questions or if my explanation isn't clear. |
@spartan563 thanks so much for the explanation! |
Good evening, My app is on firebase (node.js), and I had the same problem. I changed the way I imported @sendgrid I also set up single sender verification on app.sendgrid.com. Before: After:
|
@dougadriquei I'm having the same problem, but According to SendGrid's docs Single Sender Verification doesn't apply to me. Turns out |
Hello How could i use it in Typescript ? thank you |
i found the solution:
|
Issue Summary
I cannot import and use the type definitions from
@sendgrid/mail
with TS v2.8.1. Very likely that I've just misunderstood, but have tried a few things after reading theindex.d.ts
.Seems the type I would like is
MailService & { MailService: MailService; }
, so saystsc
if I try to arbitrarily assert something like:Steps to Reproduce
Doesn't work:
Also doesn't work:
Technical details:
tsconfig.json:
Mentioned this in #476 - thought it might be related.
The text was updated successfully, but these errors were encountered: