Home > front end >  Annotate one (or more) values in a typescript string literal union as deprecated
Annotate one (or more) values in a typescript string literal union as deprecated

Time:02-10

I know it's possible to annotate entire properties as deprecated, but is it possible to annotated one (or more) single values within a string union as deprecated?

For example, given this type declaration:

export type BoxProps = HTMLAttributes<HTMLDivElement> & {
  /**
   * @deprecated rounded has no effect and will be removed in a future version
   */
  rounded?: boolean;
  variant?:
    | 'neutral'
    | 'grey'
    | 'success'
    | 'warning';
  thickBorder?: boolean;
};

...my IDE (VS Code) will warn me that the rounded param is deprecated and will show it as visually "crossed out".

But If I try to annotate one single value of the variant string literal union type, my IDE will suggest all possible options with no warnings or visual treatments indicating that any string is deprecated:

TypeScript
export type BoxProps = HTMLAttributes<HTMLDivElement> & {
  /**
   * @deprecated rounded has no effect and will be removed in a future version
   */
  rounded?: boolean;
  variant?:
    | 'neutral'
    /** @deprecated */
    | 'grey'
    | 'success'
    | 'warning';
  thickBorder?: boolean;

// or 

TypeScript
export type BoxProps = HTMLAttributes<HTMLDivElement> & {
  /**
   * @deprecated rounded has no effect and will be removed in a future version
   */
  rounded?: boolean;
  variant?:
    | 'neutral'
    | 'grey' /** @deprecated */
    | 'success'
    | 'warning';
  thickBorder?: boolean;
};

// or 

TypeScript
export type BoxProps = HTMLAttributes<HTMLDivElement> & {
  /**
   * @deprecated rounded has no effect and will be removed in a future version
   */
  rounded?: boolean;
  variant?:
    | 'neutral'
    | /** @deprecated */ 'grey' 
    | 'success'
    | 'warning';
  thickBorder?: boolean;
};

Is this just not possible? Or is there some other syntax that needs to be used to annotate single strings as deprecated? (Or am I missing a VS Code plugin?)

CodePudding user response:

I don't think this is possible with TSDoc in Visual Studio Code. I've tried it in my IDE (Visual Studio Code), with no success.

However, there is a GitHub Issue about the same issue with a function parameter instead. Even though it isn't with union types, it might help a little. Just click here!

CodePudding user response:

@depecated support has landed with TS 4.0 in 2020.

It was discussed on the ticket about it, but no at the moment union and insertion type members don't support TSDoc at all.

  • Related