twilio-node icon indicating copy to clipboard operation
twilio-node copied to clipboard

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

Open sattarab opened this issue 2 years ago • 4 comments

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

sattarab avatar May 31 '23 14:05 sattarab

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.

charan678 avatar Jun 02 '23 05:06 charan678

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

jfbaquerocelis avatar Nov 02 '23 13:11 jfbaquerocelis

Adding the following to my tsconfig.json fixed the issue

"compilerOptions": {
  "esModuleInterop": true
}

leangl avatar Dec 20 '23 16:12 leangl

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

RobWelbourn avatar Jun 11 '24 00:06 RobWelbourn