-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
minor jsdoc improvements #1910
minor jsdoc improvements #1910
Conversation
@@ -586,7 +584,7 @@ module.exports = Receiver; | |||
/** | |||
* Builds an error object. | |||
* | |||
* @param {(Error|RangeError)} ErrorCtor The error constructor | |||
* @param {(typeof Error|typeof RangeError)} ErrorCtor The error constructor |
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.
Why typeof
? It should be the Error
or RangeError
constructor.
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.
from VS code (TypeScript) perspective it looks at @param {Error}
to be a instance of a Error class, when using typeof then it knows that it can be a Class
@@ -9,14 +9,17 @@ const { mask: applyMask, toBuffer } = require('./buffer-util'); | |||
|
|||
const mask = Buffer.alloc(4); | |||
|
|||
|
|||
/** @typedef {import('net').Socket} Socket */ |
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.
This could also be a tls.Socket
. Also, no TypeScript-specific syntax please.
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 tried tls.Socket, didn't work so well... it could not figure out the correct NodeJS namespace
also typedef is a jsdoc thing
I don't like TypeScript syntax either, very much prefer checkJs + jsDoc combo
if you are running VS-code you can try adding a comment on top and see if you get any benefit from using
// @ts-check
at the top of the file
https://www.dandoescode.com/blog/using-typescript-without-typescript/
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.
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.
From the comments:
This is TypeScript-specific syntax. Vote for github.com/jsdoc/jsdoc/issues/1645.
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.
oh, look at that...
anyway another way could be to import a unused variable
var http = require('http')
* @param {http.Server}
function foo() {
}
Best if you have treeshaking support for this case
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.
That's acceptable. However we might need to add an eslint comment for unused variables.
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.
How should we proceed here? Using {net.Socket}
seems more popular than {import('net').Socket}
even if it doesn't work perfectly (when net
is not required).
I would prefer to just improve the existing type with tls.Socket
:
@param {(net.Socket|tls.Socket)} socket The connection socket
@@ -9,13 +9,14 @@ const WebSocket = require('./websocket'); | |||
const { format, parse } = require('./extension'); | |||
const { GUID, kWebSocket } = require('./constants'); | |||
|
|||
|
|||
/** @typedef {import('http').Server} Server */ |
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.
Ditto.
WebSocket.CONNECTING = 0 | ||
WebSocket.OPEN = 1 | ||
WebSocket.CLOSING = 2 | ||
WebSocket.CLOSED = 3 | ||
|
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.
Why this change? It is already done by Object.defineProperty(WebSocket, readyState, descriptor);
below.
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.
VS inteligens could not figure out what dynamically assigned properties meant
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 prefer to not have changes only required for TypeScript / Visual Studio Code IntelliSense.
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.
Do you have any other jsDoc solution up your sleeve that describes WebSocket to have this properties?
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.
It's weird but something like this should work:
/**
* Class representing a WebSocket.
*
* @property {Number} CONNECTING description
*/
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.
forgot about that thing
readyStates.forEach((readyState, i) => { | ||
const descriptor = { enumerable: true, value: i }; | ||
const descriptor = { enumerable: true, value: i, configurable: false, writable: false }; |
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.
Why this change? false
is the default value for configurable
and writable
.
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.
when i assigned the WebSocket.CLOSING = 2
it probably changed the configurable to true, so i had to override it again - test was failing if i didn't do this
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.
What test? Behavior is tested here
Lines 102 to 111 in 0ad1f9d
it('is enumerable property of class', () => { | |
const descriptor = Object.getOwnPropertyDescriptor(WebSocket, state); | |
assert.deepStrictEqual(descriptor, { | |
configurable: false, | |
enumerable: true, | |
value: readyStates[state], | |
writable: false | |
}); | |
}); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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.
Ah I understand now, this happens due to #1910 (comment). I guess that is another reason to avoid that change.
@@ -586,7 +584,7 @@ module.exports = Receiver; | |||
/** | |||
* Builds an error object. | |||
* | |||
* @param {(Error|RangeError)} ErrorCtor The error constructor | |||
* @param {(typeof Error|typeof RangeError)} ErrorCtor The error constructor |
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.
* @param {(typeof Error|typeof RangeError)} ErrorCtor The error constructor | |
* @param {function(new:Error|RangeError)} ErrorCtor The error constructor |
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.
👍
@jimmywarting are you ok with #1912? |
closing mine b/c it's superseeded and i'm overwhelmed with other work right now |
I use this settings on by default in VS code
It was showing red lines a bit here and there. With this changes it could figure out more what things where with autocompletion
Could improve some bits even further if i may use private fields, But it requires node v12 and you are testing v8...
could we perhaps drop some older versions and align a bit more with current targeted support versions?