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

Incorrect Typescript types on MessageInstance

Open eugene-kim opened this issue 5 years ago • 10 comments

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.

image

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

declare class MessageInstance extends SerializableClass {
  /**
   * Initialize the MessageContext
   *
   * @param version - Version of the resource
   * @param payload - The instance payload
   * @param accountSid - The SID of the Account that created the resource
   * @param sid - The unique string that identifies the resource
   */
  constructor(version: V2010, payload: MessagePayload, accountSid: string, sid: string);

  private _proxy: MessageContext;
  accountSid: string;
  apiVersion: string;
  body: string;
  dateCreated: Date;
  dateSent: Date;
  dateUpdated: Date;
  direction: MessageDirection;
  errorCode: number;
  errorMessage: string;
  ...
}

to the sample JSON response in the documentation:

{
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "api_version": "2010-04-01",
  "body": "body",
  "date_created": "Thu, 30 Jul 2015 20:12:31 +0000",
  "date_sent": "Thu, 30 Jul 2015 20:12:33 +0000",
  "date_updated": "Thu, 30 Jul 2015 20:12:33 +0000",
  "direction": "outbound-api",
  "error_code": null,
  "error_message": null,
  "from": "+15017122661",
  "messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "num_media": "0",
  "num_segments": "1",
  "price": null,
  "price_unit": null,
  "sid": "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "status": "sent",
  "subresource_uris": {
    "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media.json"
  },
  "to": "+15558675310",
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json"
}

Exception/Log

# paste exception/log here

Technical details:

  • twilio-node version: v3.49.0
  • node version: 12.8.3

eugene-kim avatar Aug 26 '20 00:08 eugene-kim

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.

eshanholtz avatar Aug 27 '20 19:08 eshanholtz

@eshanholtz is there a source of truth one can use as a reference for the Message Resource schema? It would help anyone looking to create a PR or have a temporary work around for the type discrepancies.

eugene-kim avatar Aug 27 '20 22:08 eugene-kim

The source of truth is internal (and only has error_code marked as nullable). I've submitted an internal ticket to get the others updated as nullable (ref MSG-6006), but changes are also needed in the code generator to handle null-ables properly.

childish-sambino avatar Aug 28 '20 15:08 childish-sambino

UPDATE: fixed this by deleting my package-lock.json file ... looks like it was a DefinitelyTyped @types/express issue ... — Seeing similar TypeScript compilation errors when deploying firebase functions:

Type 'P' does not satisfy the constraint 'Params'.
Type 'P' is not assignable to type 'ParamsArray'.

relating to

extends core.ErrorRequestHandler<P, ResBody, ReqBody, ReqQuery> { }
interface Request<P = core.ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = core.Query> extends core.Request<P, ResBody, ReqBody, ReqQuery> { }
interface RequestHandler<P = core.ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = core.Query> extends core.RequestHandler<P, ResBody, ReqBody, ReqQuery> { }

Downgrading from 3.49.1 to 3.49.0 does not seem to help ...

Deploying functions to a Node.js 10 environment ...

Probably worth noting that firebase still uses tslint, not eslint for Typescript projects

sambecker avatar Sep 10 '20 20:09 sambecker

Couple more mistyped fields on MessageInstance:

  • from should bestring | null
  • dateSent should be Date | null

sbdchd avatar May 18 '21 18:05 sbdchd

10 months open now folks. Additionally, MessageInstance is all over this codebase, but there's no direct export in the Twilio lib, so importing the type is problematic and requires a path import, which is fragile and an antipattern.

shellscape avatar Jun 09 '21 13:06 shellscape

+1

tsongas avatar Aug 27 '22 00:08 tsongas

+1

davingee avatar Dec 28 '22 00:12 davingee

not fixed yet

shekspir55 avatar Aug 02 '23 06:08 shekspir55