Is it possible to mark something as deprecated in typescript?
Asked Answered
V

1

239

I'm writing typescript definitions for a Javascript API with a deprecated method. Here's an extract of the documentation (they say API but it's just about this single method):

This API has no effect. It has been maintained for compatibility purpose.

For compatibility purposes, I would also like to document this method in the definitions file. But if possible, I would like to communicate somehow, that it has been deprecated.

While my current issue is only about deprecation in a definitions file, I would also like to use this feature in other code. So the question is more general: How can I mark something as deprecated in typescript?

Vestment answered 19/3, 2020 at 10:53 Comment(1)
Take a look at github.com/microsoft/TypeScript/issues/390Electromagnet
V
433

You can use JSDoc comments to mark deprecated code:

/**
 * @deprecated The method should not be used
 */
export const oldFunc = () => {}

Also, this eslint rule can look through the deprecated methods and warn about their usage.

Virginium answered 20/7, 2020 at 8:40 Comment(4)
FYI, VSCode has support for this @deprecated JSDoc tag as of v1.49 code.visualstudio.com/updates/…Zacek
Do you know how can this be used for values of union types?Organist
It works, but only at the Editor level. What I need is a warning issued in the compilation messages.Villosity
@DanielLobo If you have eslint set up, you will get a warning/error, depending on the configurationVirginium

© 2022 - 2024 — McMap. All rights reserved.