In the following example, VS Code 1.77.3 and TypeScript 5.0.4 does not seem to pick up the @deprecated
tag and I do not understand why? The use case is to mark the lodash template
function as deprecated.
t1.ts:
import _template from 'lodash/template'; // eslint-disable-line @typescript-eslint/no-restricted-imports
export {
/** @deprecated Deprecated. Use JavaScript template string instead. */
_template as template
};
/** @deprecated Deprecated. */
export const func = (): void => {};
t2.ts:
import * as _ from './t1';
_.template('');
_.func();
Please also note that when using the _.template
function VS Code correctly marks the template
function as deprecated by crossing it out and also shows the additional comment in the help popup.
When the function has been completed it seems to forget that it is deprecated and no longer shows it crossed out.
2
Answers
Please try
Okay. Now that you’ve shown info about how you’re trying to use the function, I think I see what’s going on. (moral of story: save everyone their time and always start by providing a MRE).
When you re-export with overridden docs, the overriding docs will only show up when you import from the re-export– not when you import from the original export.
To elaborate on why:
See Override JSDoc for re-exported types / enum / classes / interfaces
#42684, where the general functionality of overriding JSDocs for re-exports was requested, and later implemented in feat(42684): Override JSDoc for re-exported types / enum / classes / interfaces #47293. The merge of that PR into the main branch of TypeScript happened on Jan 25th of 2022. While the issue ticket and PR have no associated milestone, that’s just a bit before the time that TypeScript 4.6 Beta was released, so I wouldn’t be surprised if this functionality was in TypeScript 4.6 or 4.7.
At the time of this writing, VS Code’s bundled TypeScript (which it uses by default for IntelliSense) is already at TypeScript version 5.0.
Strangely, I noticed that this feature as implemented doesn’t seem to actually allow completely overriding the docs. The docs are overridden at the site of the re-export, but not at the site of the import from the re-export except that the
@deprecated
tag is added, which seems like a bug to me.For your reference / learning purposes, this info was found by googling "
github typescript issues mark reexport as deprecated
".I have raised a bug report of my own here: "Overriding" JSDoc at re-exports mostly only results in propagation of added "@deprecated" JSDoc tag #53960. The asker of the question here also raised on here: Re-exported symbol marked with deprecated doesn’t get correct deprecation highlighting #53754 (for which a fix has been made).