Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Typescript types on MessageInstance #606

Open
eugene-kim opened this issue Aug 26, 2020 · 9 comments
Open

Incorrect Typescript types on MessageInstance #606

eugene-kim opened this issue Aug 26, 2020 · 9 comments
Labels
code-generation issue deals with generated code status: help wanted requesting help from the community type: bug bug in the library

Comments

@eugene-kim
Copy link

eugene-kim commented Aug 26, 2020

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
@eshanholtz eshanholtz added code-generation issue deals with generated code status: help wanted requesting help from the community type: bug bug in the library labels Aug 27, 2020
@eshanholtz
Copy link
Contributor

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.

@eugene-kim
Copy link
Author

@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.

@childish-sambino
Copy link
Contributor

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.

@sambecker
Copy link

sambecker commented Sep 10, 2020

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

@sbdchd
Copy link

sbdchd commented May 18, 2021

Couple more mistyped fields on MessageInstance:

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

@shellscape
Copy link

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.

@tsongas
Copy link

tsongas commented Aug 27, 2022

+1

@davingee
Copy link

+1

@shekspir55
Copy link

not fixed yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-generation issue deals with generated code status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

9 participants