-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
doc: correctly use integer
vs number
#59421
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
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
If |
Firstly, a user may not know there is a difference, if it ultimately resolves to Secondly, we don't use it that way. For example, Line 110 in a73b575
number type is used.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #59421 +/- ##
=======================================
Coverage 89.91% 89.91%
=======================================
Files 655 655
Lines 192866 192866
Branches 37806 37803 -3
=======================================
+ Hits 173412 173420 +8
+ Misses 12015 12006 -9
- Partials 7439 7440 +1
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree that this minimize confusion, I'd say the contrary. Adding a request for changes so this doesn't land without some data to corroborate that affirmation.
The way I see it, this is not ideal for a few reasons:
|
The thing is that JavaScript doesn't have the "notion" of Although the term Integer is never used, nor it is Float and Double, as JavaScript treats them equally, it's interesting that I do agree that referencing to |
We do have validators for integers specifically, also we interact with C++ code for which node/lib/internal/validators.js Lines 94 to 128 in 0fd1ecd
|
Duly noted. I was referring to arguments of functions that I've used before and passed non-integers or what I assuked were non-integers, and it accepted them well. Thanks for correcting me, tho. I bet that the functions that interact with the C++ counterparts either had casting or validation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saying an integer is very different than a number, and even the JS internal representation would be different. In some cases (JS only APIs), ai think we handle both and likely it’s possible for changing it, but not in the general case.
@avivkeller would be open to change this PR to only change the integer to number on places where actually any number is allowed? Makes sense to keep integers for places that are actually only integers as @aduh95 and @mcollina mentioned 👀 |
FWIW, there is no |
The current documentation tool would link integer in the types to https://webidl.spec.whatwg.org/#dfn-integer-type by the way. For example see https://nodejs.org/api/process.html#event-exit - I think beginners would be able to figure out if they click the link. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Not sure why the JSDoc is brought up here. The documents in |
Okay, I'll adjust the PR to make the distinction between the primitives more accurate (that is, using integer when an integer is needed, and number when a float is needed) |
3bb574e
to
05e02e6
Compare
integer
with number
integer
vs number
05e02e6
to
8569ea8
Compare
@@ -387,7 +387,7 @@ Resolves the given `address` and `port` into a host name and service using | |||
the operating system's underlying `getnameinfo` implementation. | |||
|
|||
If `address` is not a valid IP address, a `TypeError` will be thrown. | |||
The `port` will be coerced to a number. If it is not a legal port, a `TypeError` | |||
The `port` will be coerced to a integer. If it is not a legal port, a `TypeError` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `port` will be coerced to a integer. If it is not a legal port, a `TypeError` | |
The `port` will be coerced to an integer. If it is not a legal port, a `TypeError` |
|
||
Resolves the given `address` and `port` into a host name and service using | ||
the operating system's underlying `getnameinfo` implementation. | ||
|
||
If `address` is not a valid IP address, a `TypeError` will be thrown. | ||
The `port` will be coerced to a number. If it is not a legal port, a `TypeError` | ||
The `port` will be coerced to a integer. If it is not a legal port, a `TypeError` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `port` will be coerced to a integer. If it is not a legal port, a `TypeError` | |
The `port` will be coerced to an integer. If it is not a legal port, a `TypeError` |
The `Error.stackTraceLimit` property specifies the number of stack frames, | ||
coerced to the nearest integer, collected by a stack trace (whether generated | ||
by `new Error().stack` or `Error.captureStackTrace(obj)`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that true? It's at least incomplete given you can set it to Infinity
which doesn't have a nearest integer. Let's not talk about coerce, let's just say it's a maximum
The `Error.stackTraceLimit` property specifies the number of stack frames, | |
coerced to the nearest integer, collected by a stack trace (whether generated | |
by `new Error().stack` or `Error.captureStackTrace(obj)`). | |
The `Error.stackTraceLimit` property specifies the maximum number of stack | |
frames collected by a stack trace (whether generated by `new Error().stack` or | |
`Error.captureStackTrace(obj)`). |
@@ -1801,7 +1801,7 @@ process.nextTick(() => ac.abort()); | |||
added: v15.4.0 | |||
--> | |||
|
|||
* `n` {number} A non-negative number. The maximum number of listeners per | |||
* `n` {integer} A non-negative number. The maximum number of listeners per |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `n` {integer} A non-negative number. The maximum number of listeners per | |
* `n` {number} A non-negative number. The maximum number of listeners per |
@@ -1283,7 +1283,7 @@ added: | |||
--> | |||
|
|||
* `emitterOrTarget` {EventEmitter|EventTarget} | |||
* Returns: {number} | |||
* Returns: {integer} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Returns: {integer} | |
* Returns: {number} |
@@ -2543,7 +2543,7 @@ of event listeners registered for the `type`. | |||
added: v14.5.0 | |||
--> | |||
|
|||
* `n` {number} | |||
* `n` {integer} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `n` {integer} | |
* `n` {number} |
@@ -2554,7 +2554,7 @@ of max event listeners as `n`. | |||
added: v14.5.0 | |||
--> | |||
|
|||
* Returns: {number} | |||
* Returns: {integer} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Returns: {integer} | |
* Returns: {number} |
@@ -364,7 +364,7 @@ that determine socket reusability. | |||
added: v0.11.7 | |||
--> | |||
|
|||
* Type: {number} | |||
* Type: {integer} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Type: {integer} | |
* Type: {number} |
@@ -376,7 +376,7 @@ state. | |||
added: v0.3.6 | |||
--> | |||
|
|||
* Type: {number} | |||
* Type: {integer} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Type: {integer} | |
* Type: {number} |
@@ -389,7 +389,7 @@ added: | |||
- v12.19.0 | |||
--> | |||
|
|||
* Type: {number} | |||
* Type: {integer} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Type: {integer} | |
* Type: {number} |
@@ -1101,7 +1101,7 @@ const hasContentType = request.hasHeader('content-type'); | |||
|
|||
### `request.maxHeadersCount` | |||
|
|||
* Type: {number} **Default:** `2000` | |||
* Type: {integer} **Default:** `2000` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Type: {integer} **Default:** `2000` | |
* Type: {number} **Default:** `2000` |
@@ -1853,7 +1853,7 @@ added: v5.7.0 | |||
added: v0.7.0 | |||
--> | |||
|
|||
* Type: {number} **Default:** `2000` | |||
* Type: {integer} **Default:** `2000` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Type: {integer} **Default:** `2000` | |
* Type: {number} **Default:** `2000` |
@@ -1911,7 +1911,7 @@ explicitly. | |||
added: v16.10.0 | |||
--> | |||
|
|||
* Type: {number} Requests per socket. **Default:** 0 (no limit) | |||
* Type: {integer} Requests per socket. **Default:** 0 (no limit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Type: {integer} Requests per socket. **Default:** 0 (no limit) | |
* Type: {number} Requests per socket. **Default:** 0 (no limit) |
@@ -1932,7 +1932,7 @@ changes: | |||
description: The default timeout changed from 120s to 0 (no timeout). | |||
--> | |||
|
|||
* Type: {number} Timeout in milliseconds. **Default:** 0 (no timeout) | |||
* Type: {integer} Timeout in milliseconds. **Default:** 0 (no timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Type: {integer} Timeout in milliseconds. **Default:** 0 (no timeout) | |
* Type: {number} Timeout in milliseconds. **Default:** 0 (no timeout) |
There are way too many changes to properly review them, please split it into several PRs. |
The
integer
type is an alias ofnumber
in our documentation, and isn't a valid JavaScript type. So, as to minimize confusion, the correct type (number
) should be used instead.