Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to mark something as deprecated in typescript?

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?

like image 914
lhk Avatar asked Mar 19 '20 10:03

lhk


People also ask

How do you mark a function as deprecated in typescript?

Usually when you need to deprecate a function you would add a @deprecated notice to the function, then create a new function with probably a similar or different name and point developers to use the new function in the JSDoc message and/or display a console warning.

How do you mark a deprecated code?

Using the @Deprecated Annotation To use it, you simply precede the class, method, or member declaration with "@Deprecated." Using the @Deprecated annotation to deprecate a class, method, or field ensures that all compilers will issue warnings when code uses that program element.

How do you deprecate?

To deprecate a class or method, use the @deprecated tag, as explained in How to Write Doc Comments for JavaDoc. The paragraph following the @deprecated tag should explain why the item has been deprecated and suggest how the user can avoid using it.

What is a deprecated object?

In information technology (IT), deprecation means that although something is available or allowed, it is not recommended or that -- in the case where something must be used -- to say it is deprecated means that its failings are recognized.


1 Answers

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.

like image 118
Vladyslav Zavalykhatko Avatar answered Sep 22 '22 12:09

Vladyslav Zavalykhatko