twilio / twilio-node

Node.js helper library
MIT License
1.39k stars 509 forks source link

Twilio client is of type of any when using Twilio import in typescript #935

Open sattarab opened 1 year ago

sattarab commented 1 year ago

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:

charan678 commented 1 year ago

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.

jfbaquerocelis commented 11 months ago

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 any value. eslint(@typescript-eslint/no-unsafe-assignment)

Technical details:

twilio-node version: v4.19.0 node version: v16.18.0

leangl commented 9 months ago

Adding the following to my tsconfig.json fixed the issue

"compilerOptions": {
  "esModuleInterop": true
}
RobWelbourn commented 3 months ago

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 }
    )
}