Skip to content
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

Improve JSDoc-inferred types #1912

Merged
merged 1 commit into from Jul 7, 2021
Merged

Improve JSDoc-inferred types #1912

merged 1 commit into from Jul 7, 2021

Conversation

@lpinca
Copy link
Member

@lpinca lpinca commented Jul 6, 2021

Refs: #1910

@lpinca lpinca mentioned this pull request Jul 6, 2021
@lpinca lpinca force-pushed the improve/jsdoc branch 2 times, most recently from 222563b to 8696a9d Jul 6, 2021
Copy link

@jimmywarting jimmywarting left a comment

LGTM


const PerMessageDeflate = require('./permessage-deflate');
const WebSocket = require('./websocket');
const { format, parse } = require('./extension');
const { GUID, kWebSocket } = require('./constants');

/** @typedef {import('http').Server} Server */
/** @typedef {import('http').IncomingMessage} IncomingMessage */
/** @typedef {import('net').Socket} Socket */
Copy link

@jimmywarting jimmywarting Jul 6, 2021

if you already require('http') then you don't need typedef?

lib/websocket.js Outdated
* @property {Number} CONNECTING The connection is not yet open
* @property {Number} OPEN The connection is open and ready to communicate
* @property {Number} CLOSING The connection is in the process of closing
* @property {Number} CLOSED The connection is closed

tried this also, didn't work for me, maybe it's the right way to do it...

what did work was:

class X {
  static CONNECTING = 1
  CONNECTING = 1
}

or like a mention earlier: x.CONNECTING = 1
but then it dose not have the right descriptor (unless you add those with defineProperties)

Copy link
Member Author

@lpinca lpinca Jul 6, 2021

Does it work with

Object.defineProperty(WebSocket.prototype, 'CONNECTING', { enumerable: true, value: 0 });
Object.defineProperty(WebSocket, 'CONNECTING', { enumerable: true, value: 0 });

(without the loop)?

Copy link
Member Author

@lpinca lpinca Jul 6, 2021

The same pattern is also used here https://github.com/websockets/ws/blob/7.5.2/lib/websocket.js#L402-L411. I'm not sure I want to change it. It is not a JSDoc issue. It is simply not documented/commented :)

without the loop it did work fine doing just

Object.defineProperty(WebSocket.prototype, 'CONNECTING', { enumerable: true, value: 0 });

tried it if it would work with a object using defineProperties

Object.defineProperties(WebSocket, {
  CONNECTING: {
    enumerable: true,
    value: 0
  }
});

The result: Property 'CONNECTING' does not exist on type 'typeof WebSocket'

@lpinca lpinca force-pushed the improve/jsdoc branch from 8696a9d to a8cdb46 Jul 7, 2021
@lpinca lpinca changed the title Improve JSDoc comments Improve JSDoc-inferred types Jul 7, 2021
@lpinca
Copy link
Member Author

@lpinca lpinca commented Jul 7, 2021

@lpinca lpinca force-pushed the improve/jsdoc branch from a8cdb46 to a1e0901 Jul 7, 2021
@jimmywarting
Copy link

@jimmywarting jimmywarting commented Jul 7, 2021

LGTM

@lpinca lpinca merged commit ecb9d9e into master Jul 7, 2021
65 checks passed
@lpinca lpinca deleted the improve/jsdoc branch Jul 7, 2021
@lpinca
Copy link
Member Author

@lpinca lpinca commented Jul 7, 2021

Thank you for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants