Conversation
| * 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.
Why typeof? It should be the Error or RangeError constructor.
There was a problem hiding this comment.
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
| const mask = Buffer.alloc(4); | ||
|
|
||
|
|
||
| /** @typedef {import('net').Socket} Socket */ |
There was a problem hiding this comment.
This could also be a tls.Socket. Also, no TypeScript-specific syntax please.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
From the comments:
This is TypeScript-specific syntax. Vote for github.com/jsdoc/jsdoc/issues/1645.
There was a problem hiding this comment.
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.
That's acceptable. However we might need to add an eslint comment for unused variables.
There was a problem hiding this comment.
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
| const { GUID, kWebSocket } = require('./constants'); | ||
|
|
||
|
|
||
| /** @typedef {import('http').Server} Server */ |
| WebSocket.CONNECTING = 0 | ||
| WebSocket.OPEN = 1 | ||
| WebSocket.CLOSING = 2 | ||
| WebSocket.CLOSED = 3 | ||
|
|
There was a problem hiding this comment.
Why this change? It is already done by Object.defineProperty(WebSocket, readyState, descriptor); below.
There was a problem hiding this comment.
VS inteligens could not figure out what dynamically assigned properties meant
There was a problem hiding this comment.
I prefer to not have changes only required for TypeScript / Visual Studio Code IntelliSense.
There was a problem hiding this comment.
Do you have any other jsDoc solution up your sleeve that describes WebSocket to have this properties?
There was a problem hiding this comment.
It's weird but something like this should work:
/**
* Class representing a WebSocket.
*
* @property {Number} CONNECTING description
*/
|
|
||
| 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.
Why this change? false is the default value for configurable and writable.
There was a problem hiding this comment.
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.
What test? Behavior is tested here
Lines 102 to 111 in 0ad1f9d
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Ah I understand now, this happens due to #1910 (comment). I guess that is another reason to avoid that change.
| * 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.
| * @param {(typeof Error|typeof RangeError)} ErrorCtor The error constructor | |
| * @param {function(new:Error|RangeError)} ErrorCtor The error constructor |
|
@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?