如何在 @typedef 中标记已弃用的属性?

ᆼᆺᆼ*_*ᆼᆺᆼ 2 javascript jsdoc tsdoc

我想将一个属性(例如qux下面的)标记为已弃用:

/**
 @typedef {object} Foo
 @property {string} bar
 @property {symbol} qux - How to deprecate it?
 @deprecated @property {symbol} qux2 - Doesn't work
 @property {symbol} qux3 @deprecated - This marks the whole of Foo as deprecated 
 */
Run Code Online (Sandbox Code Playgroud)

我应该提到,我想在 JSDoc 注释中执行此操作,而不是使用 TypeScript。

Ars*_*ano 6

根据tsdoc 上的Issue#131@deprecated ,您实际上可以使用属性,只需将其设置在对象内部(也适用于 JS)。

例如:

/**
 * Explain the interface ...
 */
export interface test {
    /**
     * Foo property
     */
    Foo: string;
    /**
     * @deprecated Use {@link test.qux2} instead.
     */
    qux: string;
    /**
     * qux2 property
     */
    qux2: string;
}
Run Code Online (Sandbox Code Playgroud)

结果是:

在此输入图像描述


在课程中,例如:

/**
 * Explain the interface ...
 */
export interface test {
    /**
     * Foo property
     */
    Foo: string;
    /**
     * @deprecated Use {@link test.qux2} instead.
     */
    qux: string;
    /**
     * qux2 property
     */
    qux2: string;
}
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

使用已弃用的属性时。 在此输入图像描述