Invalid types for nested fields
Problem
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: [code block] [code block] `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
Unverified for your environment
Select your OS to check compatibility.
2 Fixes
Treat Twilio nested fields as nullable/union types until codegen is fixed upstream
Generated-types mismatch: API payload stays in snake_case for some fields while exported TypeScript types assume camelCase normalization, and nullable fields are not reflected accurately in the generated type surface.
Awaiting Verification
Be the first to verify this fix
- 1
Identify mismatched fields
Identify nested fields where snake_case vs camelCase normalization is inconsistent.
- 2
Wrap in local type narrowing
Model affected fields as nullable or union types in local wrappers rather than trusting the generated types directly.
- 3
Add runtime narrowing guards
Add explicit runtime checks or type guards for fields that may be undefined or wrongly typed.
Validation
TypeScript compilation passes and runtime field access is safe with explicit narrowing.
Verification Summary
Sign in to verify this fix
1 low-confidence fix
Normalize Nested Field Types in Twilio Pricing API
The issue arises from inconsistent naming conventions and lack of proper type definitions in the Twilio SDK. Specifically, the field 'current_price' is not being converted to 'currentPrice', and the nullable nature of 'inboundCallPrice' is not reflected in the type definition, leading to potential runtime errors.
Awaiting Verification
Be the first to verify this fix
- 1
Update Type Definitions
Modify the TypeScript definition for 'NumberInstance' to ensure that 'currentPrice' is correctly defined and that 'inboundCallPrice' is marked as nullable.
typescriptinterface NumberInstance { currentPrice: number; inboundCallPrice?: number | null; } - 2
Implement Normalization Logic
Add a normalization function to convert 'current_price' to 'currentPrice' when mapping API responses to the TypeScript types.
typescriptfunction normalizeNumberInstance(data: any): NumberInstance { return { currentPrice: data.current_price, inboundCallPrice: data.inbound_call_price || null }; } - 3
Update API Response Handling
Ensure that the API response handling code utilizes the normalization function to correctly map the API response to the updated type definitions.
typescriptconst numberInstance = normalizeNumberInstance(apiResponse); - 4
Run Unit Tests
Create or update unit tests to verify that the normalization logic works as expected and that the types are correctly reflected in the output.
typescriptit('should normalize API response correctly', () => { const apiResponse = { current_price: 10, inbound_call_price: null }; const result = normalizeNumberInstance(apiResponse); expect(result.currentPrice).toBe(10); expect(result.inboundCallPrice).toBeNull(); });
Validation
Run the updated unit tests to ensure they pass without errors. Additionally, verify the API response in a development environment to confirm that the fields are correctly normalized and typed.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep