Skip to content
Advertisement

SendGrid client TypeScript Error: HttpMethod

I have:

JavaScript

But my TypeScript language server gives me an error about sendgridRequest:

JavaScript

Is there some way to resolve this?

Advertisement

Answer

method: 'PUT' in your object is being inferred as string, but it’s expecting specific strings like "PUT" | "GET" | "POST". This because it has no specific type to try to match, and by default specific strings are just inferred as string.

You can probably fix this by passing your object directly to the function. This casts the object as the right type because it’s checked against what that function accepts:

JavaScript

Or you can give your intermediate variable the correct type imported from the sendgrid module.

JavaScript

I wasn’t able to test this because this module doesn’t seem import into the typescript playground but I think that should work.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement