skip to Main Content

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.

enter image description here

When the function has been completed it seems to forget that it is deprecated and no longer shows it crossed out.

enter image description here

2

Answers


  1. Please try

    import _template from 'lodash/template';
    
    export {
    /** @deprecated Deprecated. Use JavaScript template string instead. */
    _template as template
    };
    
    Login or Signup to reply.
  2. 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.


    // exporter.js
    /** a thing */
    export const thing = "hello world!";
    
    // reexporter.js
    export {
      /** @deprecated blah blah reasons. */
      thing
    } from "./exporter";
    
    // importer.js
    import { thing } from "./reexporter"
    // ^VS Code will cross "thing" out here
    import { thing as originalThing } from "./exporter"
    // ^VS Code will cross nothing out here
    

    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).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search