You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code中JSDoc含null的联合类型hover未显示null问题

VS Code中JSDoc联合类型标注不生效问题

在VS Code中使用JSDoc配合jsconfig.json做类型检查时,定义了LinkedListNode类,其中this.next用JSDoc标注为LinkedListNode | null的联合类型,但hover该属性时,VS Code仅显示LinkedListNode,完全忽略了联合类型中的null。

我已经尝试过以下几种标注写法,均未解决问题:

  • /** @type {LinkedListNode | null} */
  • /** @type {?LinkedListNode} */
  • /** @type {(LinkedListNode|null)} */

期望hover时能正确显示完整的联合类型:LinkedListNode | null


相关代码

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;
  }
}

当前hover提示

(property) LinkedListNode.next: LinkedListNode

期望的hover提示

(property) LinkedListNode.next: LinkedListNode | null

内容的提问来源于stack exchange,提问作者user20668178

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 07:32:08