Skip to content

Improve JSDoc-inferred types#1912

Merged
lpinca merged 1 commit intomasterfrom
improve/jsdoc
Jul 7, 2021
Merged

Improve JSDoc-inferred types#1912
lpinca merged 1 commit intomasterfrom
improve/jsdoc

Conversation

@lpinca
Copy link
Copy Markdown
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
Copy Markdown

@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


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

@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
Copy link
Copy Markdown

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

Copy link
Copy Markdown

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
Copy Markdown
Member Author

lpinca commented Jul 7, 2021

@jimmywarting PTAL.

@jimmywarting
Copy link
Copy Markdown

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
Copy Markdown
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