Incorrect Typescript types on MessageInstance
Problem
Issue Summary The `MessageInstance` class looks as if it contains incorrect types for some of its instance properties. Properties such as `errorCode` and `errorMessage` can be nullable according to the documentation so I would think that the type of `errorCode` should be `number | null` rather than simply `number` as it currently is. Props types that seem incorrect: - `errorCode`: should be `number | null` rather than `number` - `errorMessage`: should be `string | null` rather than `string` - `price`: should be `string | null` rather than `string` - `priceUnit`: should be `string | null` rather than `string` - `messagingServiceSid`: should be `string | null` rather than `string` (From the docs: "The SID of the Messaging Service used with the message. The value is null if a Messaging Service was not used.") Code Snippet Compare the type of the instance property `errorCode` here [code block] to the sample JSON response in the documentation: [code block] Exception/Log [code block] Technical details: twilio-node version: `v3.49.0` node version: `12.8.3`
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Update TypeScript Types for MessageInstance Properties
The current TypeScript definitions for the MessageInstance class do not accurately reflect the nullable nature of certain properties as specified in the Twilio API documentation. This discrepancy can lead to runtime errors when null values are encountered, as TypeScript will not allow null assignments to properties defined with non-nullable types.
Awaiting Verification
Be the first to verify this fix
- 1
Modify errorCode Type
Change the type of the errorCode property from 'number' to 'number | null' to accurately represent its nullable nature.
typescripterrorCode: number | null; - 2
Modify errorMessage Type
Update the errorMessage property type from 'string' to 'string | null' to reflect that it can be null according to the documentation.
typescripterrorMessage: string | null; - 3
Modify price Type
Change the price property type from 'string' to 'string | null' to ensure it can accommodate null values.
typescriptprice: string | null; - 4
Modify priceUnit Type
Update the priceUnit property type from 'string' to 'string | null' to accurately represent its nullable nature.
typescriptpriceUnit: string | null; - 5
Modify messagingServiceSid Type
Change the messagingServiceSid property type from 'string' to 'string | null' to reflect that it can be null when a Messaging Service is not used.
typescriptmessagingServiceSid: string | null;
Validation
Run TypeScript compiler to ensure no type errors are present. Additionally, test the MessageInstance class with mock data that includes null values for the modified properties to confirm that the application handles these cases without errors.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep