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.29k stars 176 forks source link

[bug] JavaScript's floating point inaccuracy makes IDs invalid #400

Closed NyCodeGHG closed 1 year ago

NyCodeGHG commented 1 year ago

Describe the bug Due to the nature of javascripts number type being a floating point number, IDs can be inaccurate and randomly turn into another number.

To Reproduce Example with the following id: 1588987262754234368 Open your Browser's console or the node repl and paste the number.

image js screws up the number because of floating point inaccuracy

Expected behavior A clear and concise description of what you expected to happen. A number should stay the same. I would suggest using either just a string for the id or BigInt.

Version

Additional context This would be a breaking change

camiaei commented 1 year ago

hi. I'm pretty sure ids are string. could you double check?

NyCodeGHG commented 1 year ago

I should have said that I'm using API v1. here in the TweetV1 type id is a number. If IDs are strings in v2 I could switch to that

camiaei commented 1 year ago

I didn't know that in v1 they were numbers Maybe this can help you

image https://developer.twitter.com/en/docs/twitter-ids https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/tweet

NyCodeGHG commented 1 year ago

oh maybe i should have looked a bit more into my autocomplete, i'll just use id_str. thank you :)