Can't instantiate client in typescript: Only a void function can be called with the 'new' keyword
See original GitHub issueVersion: 3.19.2
Code Snippet
import * as TwilioApi from 'twilio';
const twilio = new TwilioApi('sid', 'secret');
Exception/Log
Typescript error: Only a void function can be called with the 'new' keyword
If you don’t use new
keyword, the constructor doesn’t get called and there’s a different error. I’m just going to use the REST Api directly, but this was certainly annoying/disappointing. I’d normally just ignore it, but I’m using Google Cloud functions, and don’t want to turn off their TS based safety feature, which prevents code that throws errors from deploying.
Steps to Reproduce
- Use typescript with twilio-node
- Try to instantiate a client
- Breaks
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
TS - Only a void function can be called with the 'new' keyword
I am getting this weird error from TypeScript:.
Read more >new operator - JavaScript - MDN Web Docs - Mozilla
When a function is called with the new keyword, the function will be used as a constructor. new will do the following things:....
Read more >Handbook - Classes - TypeScript
Here we create a new variable called greeterMaker . This variable will hold the class itself, or said another way its constructor function....
Read more >TypeScript Interfaces - TutorialsTeacher
This is also known as "duck typing" or "structural subtyping". An interface is defined with the keyword interface and it can include properties...
Read more >Docs • Svelte
npm create svelte@latest myapp cd myapp npm install npm run dev. SvelteKit will handle calling the Svelte compiler to convert your .svelte files...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have been using the Twilio library (see this post on sending SMS messages with Twilio in TypeScript) like this:
This picks out the actual Twilio API client.
I too am getting this issue as of Feb 2021. This removes the error for me: