PLhery / node-twitter-api-v2

Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.
https://www.npmjs.com/package/twitter-api-v2
Apache License 2.0
1.32k stars 186 forks source link

[bug] TweetEntitiesV2 properties should be optional #428

Open jam-fran opened 1 year ago

jam-fran commented 1 year ago

The type definition for TweetEntitiesV2 currently requires all properties:

export interface TweetEntitiesV2 {
    annotations: TweetEntityAnnotationsV2[];
    urls: TweetEntityUrlV2[];
    hashtags: TweetEntityHashtagV2[];
    cashtags: TweetEntityHashtagV2[];
    mentions: TweetEntityMentionV2[];
}

However, fetching a singleTweet() often returns only a partial entities object if the tweet does not contain all of the entities. For example, below is a raw entities response from Twitter that leads to a type error:

    "entities": {
      "mentions": [
        {
          "start": 229,
          "end": 239,
          "username": "Cristiano",
          "id": "155659213"
        },
        {
          "start": 257,
          "end": 267,
          "username": "AlNassrFC",
          "id": "523926217"
        }
      ],
      "urls": [
        {
          "start": 268,
          "end": 291,
          "url": "https://t.co/oan7nu8NWC",
          "expanded_url": "https://twitter.com/AlNassrFC_EN/status/1608935670520909825/photo/1",
          "display_url": "pic.twitter.com/oan7nu8NWC",
          "media_key": "3_1608935659972038657"
        },
        {
          "start": 268,
          "end": 291,
          "url": "https://t.co/oan7nu8NWC",
          "expanded_url": "https://twitter.com/AlNassrFC_EN/status/1608935670520909825/photo/1",
          "display_url": "pic.twitter.com/oan7nu8NWC",
          "media_key": "3_1608935659519049734"
        }
      ]
    },

I would make a small PR myself but I'm a noob and haven't contributed before so wouldn't be exactly sure what to do 🤦