@typescript-eslint/no-deprecated
Disallow using code marked as @deprecated
Also called typescript-eslint/no-deprecated, typescript/no-deprecated
A @deprecated tag in a doc comment says that a function, class, property or type is going away, and usually what to use instead. Editors strike the name through, but nothing stops new code from using it. This rule reports every use, and repeats the text after the tag so you know what to switch to.
It works for your own code, for packages and for the built-in types. The declaration itself and the import aren't reported, only the places where the name is used. If only one overload of a function is deprecated, only calls to that overload are reported.
Configure#
Off by default. This rule needs types, so turning it on makes bun lint type check your code first.
[lint.rules]
"@typescript-eslint/no-deprecated" = "error" # or "warn"Every option, set to its default:
[lint.rules]
"@typescript-eslint/no-deprecated" = ["error", {
allow = [], # list of strings or objects
}]Examples#
/** @deprecated Use `fetchUser` instead. */
function getUser(id: number) {}
interface Options {
/** @deprecated */
legacy?: boolean;
}
getUsergetUser is deprecated. Use fetchUser instead.(1);
function start(options: Options) {
return options.legacylegacy is deprecated.;
}Built-in methods count too:
const year = "2026-01-01".substrsubstr is deprecated. A legacy feature for browser compatibility(0, 4);/** @deprecated Use `fetchUser` instead. */
function getUser(id: number) {}
function fetchUser(id: number) {}
fetchUser(1);
const year = "2026-01-01".slice(0, 4);Only the deprecated overload:
/** @deprecated Pass a number. */
function load(id: string): void;
function load(id: number): void;
function load(id: string | number): void {}
loadload is deprecated. Pass a number.("1");
load(1);Options#
| Option | Default | What it does |
|---|---|---|
allow | [] | Deprecated names that you can keep using. |
Each allow entry is a name, or an object that also says where the name comes from:
| Entry | What it matches |
|---|---|
"getUser" | Anything with that name. |
{ "from": "file", "name": "getUser" } | A name declared in your project. Add "path" to name the file. |
{ "from": "lib", "name": "substr" } | A name from the built-in TypeScript types. |
{ "from": "package", "name": "exists", "package": "fs" } | A name from a package. |
name can also be a list of names.
{ "allow": [{ "from": "file", "name": "getUser" }] }No problems/** @deprecated Use `fetchUser` instead. */
function getUser(id: number) {}
getUser(1);{ "allow": [{ "from": "lib", "name": "substr" }] }No problemsconst year = "2026-01-01".substr(0, 4);