Twilio client is of type of any when using Twilio import in typescript
Issue Summary
When using Twilio v4 library the Twilio client is of type any.
Steps to Reproduce
import { Twilio } from "twilio/lib"
const twilio_client = new Twilio( <SID>, <AUTH> )
the type of twilio_client is any in version 4 whereas in version 3 it used to be the correct type i.e. TwilioClient.
Code Snippet
import { Twilio } from "twilio/lib"
const twilio_client = new Twilio( <SID>, <AUTH> )
Technical details:
- twilio-node version: v4
- node version: v14.17.3
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.
Hi everyone!
I started to face the same issue when I updated the twilio library from v3.x to v4.x:
import twilio from 'twilio';
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken, { accountSid: subaccountSid });
But the linter show me this rule error:
Unsafe assignment of an
anyvalue. eslint(@typescript-eslint/no-unsafe-assignment)
Technical details:
twilio-node version: v4.19.0
node version: v16.18.0
Adding the following to my tsconfig.json fixed the issue
"compilerOptions": {
"esModuleInterop": true
}
My somewhat less-than-elegant workaround was to do this:
import twilio from 'twilio';
const apiKey = process.env.TWILIO_API_KEY;
const apiSecret = process.env.TWILIO_API_SECRET;
const accountSid = process.env.TWILIO_ACCOUNT_SID;
if (apiKey && apiSecret && accountSid {
const client=new twilio.Twilio(
apiKey,
apiSecret,
{ accountSid }
)
}