typescript/no-deprecated Pedantic
Qué hace
Prohíbe using code marked as @deprecated.
¿Por qué es problemático?
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, allowing editors to visually indicate deprecated code — usually with a strikethrough. However, TypeScript doesn't report type errors for deprecated code on its own.
Ejemplos
Ejemplos de código incorrecto para esta regla:
/** @deprecated Use apiV2 instead. */
declare function apiV1(): Promise<string>;
declare function apiV2(): Promise<string>;
await apiV1(); // Using deprecated function
import { parse } from "node:url";
// 'parse' is deprecated. Use the WHATWG URL API instead.
const url = parse("/foo");Ejemplos de código correcto para esta regla:
/** @deprecated Use apiV2 instead. */
declare function apiV1(): Promise<string>;
declare function apiV2(): Promise<string>;
await apiV2(); // Using non-deprecated function
// Modern Node.js API, uses `new URL()`
const url2 = new URL("/foo", "http://www.example.com");Configuración
Esta regla acepta un objeto de configuración con las siguientes propiedades:
allow
tipo: array
predeterminado: []
An array of type or value specifiers that are allowed to be used even if deprecated. Use this to allow specific deprecated APIs that you intentionally want to continue using.
allow[n]
tipo: object | string
Type or value specifier for matching specific declarations
Supports four types of specifiers:
- String specifier (deprecated): Universal match by name
"Promise"- File specifier: Match types/values declared in local files
{ "from": "file", "name": "MyType" }
{ "from": "file", "name": ["Type1", "Type2"] }
{ "from": "file", "name": "MyType", "path": "./types.ts" }- Lib specifier: Match TypeScript built-in lib types
{ "from": "lib", "name": "Promise" }
{ "from": "lib", "name": ["Promise", "PromiseLike"] }- Package specifier: Match types/values from npm packages
{ "from": "package", "name": "Observable", "package": "rxjs" }
{ "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" }allow[n].from
tipo: "file"
allow[n].name
tipo: array | string
Name specifier that can be a single string or array of strings
allow[n].name[n]
tipo: string
allow[n].path
tipo: string
Optional file path to specify where the types or values must be declared. If omitted, all files will be matched.
Cómo usarla
To enable this rule using the config file or in the CLI, you can use:
{
"options": {
"typeAware": true
},
"rules": {
"typescript/no-deprecated": "error"
}
}import { defineConfig } from "oxlint";
export default defineConfig({
options: { typeAware: true },
rules: {
"typescript/no-deprecated": "error",
},
});oxlint --type-aware --deny typescript/no-deprecatedVersión
Esta regla se añadió en v1.26.0.