Skip to content
← Back to rules

typescript/no-deprecated Pedantic

💭 This rule requires type information.

무엇을 하나요

Disallow using code marked as @deprecated.

왜 문제인가요?

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.

예시

이 규칙에서 올바르지 않은 코드 예:

ts
/** @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");

이 규칙에서 올바른 코드 예:

ts
/** @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");

설정

이 규칙은 다음 속성을 갖는 설정 객체를 허용합니다.

allow

type: array

default: []

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]

type: object | string

Type or value specifier for matching specific declarations

Supports four types of specifiers:

  1. String specifier (deprecated): Universal match by name
json
"Promise"
  1. File specifier: Match types/values declared in local files
json
{ "from": "file", "name": "MyType" }
{ "from": "file", "name": ["Type1", "Type2"] }
{ "from": "file", "name": "MyType", "path": "./types.ts" }
  1. Lib specifier: Match TypeScript built-in lib types
json
{ "from": "lib", "name": "Promise" }
{ "from": "lib", "name": ["Promise", "PromiseLike"] }
  1. Package specifier: Match types/values from npm packages
json
{ "from": "package", "name": "Observable", "package": "rxjs" }
{ "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" }
allow[n].from

type: "file"

allow[n].name

type: array | string

Name specifier that can be a single string or array of strings

allow[n].name[n]

타입: string

allow[n].path

타입: string

Optional file path to specify where the types or values must be declared. If omitted, all files will be matched.

사용 방법

To enable this rule using the config file or in the CLI, you can use:

json
{
  "options": {
    "typeAware": true
  },
  "rules": {
    "typescript/no-deprecated": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  options: { typeAware: true },
  rules: {
    "typescript/no-deprecated": "error",
  },
});
bash
oxlint --type-aware --deny typescript/no-deprecated

버전

이 규칙은 v1.26.0에 추가되었습니다.

참고