Skip to content

[deprecation] Warns when deprecated APIs are used. #1223

Closed
@htho

Description

@htho

Repro

{
  "rules": {
    "@typescript-eslint/deprecation": ["warn"]
  }
}
// CASE 1: for functions
/** @deprecated use f2 instead */
function f1(): void {return;}
function f2(): void {return;}

f1(); // WARN: "f1 is deprecated: use f2 instead

// CASE 2: for interfaces
interface Test {
  /** @deprecated use b instead */
  public a?: string;
  public b?: string;
}

const x: Test = {
  a: "foo"; // WARN: "Test.a is deprecated: use b instead
}

Expected Result
In both cases there should be a warning, that the function or property are depricated.

Actual Result
The @depricated comments are ignored.

Additional Info
There is a TSLint Rule: deprication and a long discussion at the TypeScript Bugtracker

I did not check the implementation for TSLint, but there are many things to consider. They should be configurable.

  1. For interfaces a depricated property must be optional (otherwise one could not not use the property)
  2. There should be a warning if a private or protected property is marked as depricated. (at least private properties should be updated as soon as a property is depricated)
  3. A @depricated tag must be followed by an explanation and/or alternative.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: new plugin ruleNew rule request for eslint-pluginlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions