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 Compare July 6, 2021 19:26
Copy link

@jimmywarting jimmywarting left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 changed the title Improve JSDoc comments Improve JSDoc-inferred types Jul 7, 2021
@lpinca
Copy link
Member Author

lpinca commented Jul 7, 2021

@jimmywarting PTAL.

@jimmywarting
Copy link

LGTM

@lpinca lpinca merged commit ecb9d9e into master Jul 7, 2021
@lpinca lpinca deleted the improve/jsdoc branch July 7, 2021 11:07
@lpinca
Copy link
Member Author

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
Development

Successfully merging this pull request may close these issues.

2 participants