question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Understand 'int', 'integer', 'float', 'double', etc. as 'number' in JSDoc

See original GitHub issue

All numeric-sounding names should probably resolve to number (maybe only if no other type is defined with such a given name).

Ideas:

  • [u]int[8|16|32|64]
  • integer
  • float
  • double

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:8
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
andy-mscommented, Feb 14, 2018

This might require a breaking change later if actual ints are added.

1reaction
pilattecommented, Nov 7, 2022

Arrays in JS are objects so when you access keys with x[<key>], <key> can be anything.

> x = ['foo']
[ 'foo' ]
> x[1.5] = 'bar'
'bar'
> x
[ 'foo', '1.5': 'bar' ]
> x['test']= 15
15
> x
[ 'foo', '1.5': 'bar', test: 15 ]
> x.length
1
> x = new Int8Array(10)
Int8Array(10) [
  0, 0, 0, 0, 0,
  0, 0, 0, 0, 0
]
> x['hello'] = 15
15
> x[1.5] = "foo"
'foo'

In TS, it only checks if the key is a number so a string key will fail but 1.5 is a valid key.

Maybe int could be implemented somehow like literals. But it’s not feasible to guess if a number is an integer or not on computed variables. Typescript does not know the difference between 3/2 and 4/2. One would be a float and the other an int but it is difficult to infer this statically.

Being able to set float keys on an array and not get an error at compile time and neither at runtime is really bad but I guess that’s how it is for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understand 'int', 'integer', 'float', 'double', etc. as 'number' in ...
I think both TS and JSDoc should have a way of defining a type alias as a subset or superset of an existing...
Read more >
Use JSDoc: @type
Overview. The @type tag allows you to provide a type expression identifying the type of value that a symbol may contain, or the...
Read more >
How do I check that a number is float or integer?
@Pointy: double precision floats can represent integer values exactly up to 2^53. So it depends if the OP was asking about integer in...
Read more >
12 Amazing Types of TypeScript You Need to Know - eduCBA
We can also consider that for all types of no's like float, double, int, long int, etc we have the only number as...
Read more >
eslint-plugin-jsdoc - npm
This integer property allows one to add a fixed amount of whitespace at the beginning of the second or later lines of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found