Here is an example of a LinkedList
class definition that utilizes JSDoc and jsconfig.json
for type checking in VSCode. The issue lies in displaying the type of value
and next
as union types with undefined, which is not currently happening.
class LinkedListNode {
/**
* @param {number | undefined} value
* @param {LinkedListNode | undefined} next
*/
constructor(value, next) {
/** @type {number} */
this.value = value ?? 0;
/** @type {LinkedListNode | null} */
this.next = next ?? null;
}
}
This problem applies to all unions, but let's focus on one specific line:
/** @type {LinkedListNode | null} */
this.next = next ?? null;
Currently, the hover message on this.next
is incorrect:
(property) LinkedListNode.next: LinkedListNode
What we want to see is:
(property) LinkedListNode.next: LinkedListNode | null
I have attempted various solutions, none of which have resolved the issue:
/** @type {LinkedListNode | null} */
/** @type {?LinkedListNode} */
/** @type {(LinkedListNode|null)} */