no-deprecated
Disallow using code marked as
@deprecated
.
Extending "plugin:@typescript-eslint/strict-type-checked"
in an ESLint configuration enables this rule.
This rule requires type information to run.
The JSDoc @deprecated
tag can be used to document some piece of code being deprecated.
It's best to avoid using code marked as deprecated.
This rule reports on any references to code marked as @deprecated
.
TypeScript recognizes the @deprecated
tag and visualizes deprecated code with a strikethrough.
However, TypeScript doesn't report type errors for deprecated code on its own.
module.exports = {
"rules": {
"@typescript-eslint/no-deprecated": "error"
}
};
Try this rule in the playground ↗
Examples
- ❌ Incorrect
- ✅ Correct
/** @deprecated Use apiV2 instead. */
declare function apiV1(): Promise<string>;
declare function apiV2(): Promise<string>;
await apiV1();
Open in Playgroundimport { parse } from 'node:url';
// 'parse' is deprecated. Use the WHATWG URL API instead.
const url = parse('/foo');
Open in Playground/** @deprecated Use apiV2 instead. */
declare function apiV1(): Promise<string>;
declare function apiV2(): Promise<string>;
await apiV2();
Open in Playground// Modern Node.js API, uses `new URL()`
const url2 = new URL('/foo', 'http://www.example.com');
Open in PlaygroundOptions
This rule is not configurable.
When Not To Use It
If portions of your project heavily use deprecated APIs and have no plan for moving to non-deprecated ones, you might want to disable this rule in those portions.
Related To
import/no-deprecated
andimport-x/no-deprecated
: Does not use type information, but does also support TomDoceslint-plugin-deprecation
(deprecation/deprecation
): Predecessor to this rule in a separate plugin
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.
See Troubleshooting > Linting with Type Information > Performance if you experience performance degredations after enabling type checked rules.