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

Invalid types for nested fields

Open fcoelho opened this issue 3 months ago • 2 comments

Some of the types exported by this package aren't valid. There's a mix of variable casing and it doesn't seem like results get normalized correctly

For example in this program:

import twilio from "twilio";

async function main() {
  const client = twilio(
    process.env.TWILIO_ACCOUNT_SID,
    process.env.TWILIO_AUTH_TOKEN
  );

  const result = await client.pricing.v2.voice.numbers
    .get(process.env.DESTINATION_NUMBER ?? "")
    .fetch();

  console.log(result);
}

main().catch(console.error);
$ pnpm tsx index.ts
{
  destinationNumber: '+44xxxxxxx',
  originationNumber: null,
  country: 'United Kingdom',
  isoCountry: 'GB',
  outboundCallPrices: [
    {
      base_price: '0.03050',
      current_price: '0.03050',
      origination_prefixes: [Array]
    }
  ],
  inboundCallPrice: null,
  priceUnit: 'USD',
  url: 'https://pricing.twilio.com/v2/Voice/Numbers/+44xxxxxxx'
}

result is of type NumberInstance and it sets outboundCallPrices but the actual type of that field says a property currentPrice should exist but it's never converted from current_price into currentPrice.

inboundCallPrice can also be null, but that's not reflected in the field type: https://github.com/twilio/twilio-node/blob/7d9dd1fe9d2bc7e68f90a66e05785586ab20b270/src/rest/pricing/v2/voice/number.ts#L208

The source type descriptions in the openapi spec correctly mentions that both of these are nullable: https://github.com/twilio/twilio-oai/blob/bcf1d20ba0710f272748c3d23312498e28a99315/spec/yaml/twilio_pricing_v2.yaml#L304-L341

fcoelho avatar Oct 02 '25 08:10 fcoelho

Hello! With the latest release, this issue is resolved. Please upgrade to the latest release verion.

manisha1997 avatar Oct 14 '25 09:10 manisha1997

Hi @manisha1997 I don't think this was fixed. Just tested this with twilio 5.10.3 and got the exact same output as above. The type definitions for inbound/outbound prices are still not nullable in the main branch and there have been no changes to the number.ts file either: https://github.com/twilio/twilio-node/commits/5.10.3/src/rest/pricing/v2/voice/number.ts

Have changes been made elsewhere and not reflected in this repository yet?

fcoelho avatar Oct 14 '25 14:10 fcoelho