HiveBrain v1.2.0
Get Started
← Back to all entries
patterntypescriptCritical

Is it possible to mark something as deprecated in typescript?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
somethingpossibletypescriptmarkdeprecated

Problem

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?

Solution

You can use JSDoc comments to mark deprecated code:
/**
* @deprecated The method should not be used
*/
export const oldFunc = () => {}


plugin-deprecation can be used for ESLint to look through the deprecated methods and warn about their usage.

VSCode also supports the deprecated tag.

Context

Stack Overflow Q#60755711, score: 510

Revisions (0)

No revisions yet.