Skip to content

Rule to mark types in JSDoc as used #858

Closed
@Josh-Cena

Description

@Josh-Cena

Motivation

Consider the following code:

import type { ComponentType } from "react";

/** @see {@link ComponentType} */
export type Foo = number;

TypeScript compiler understands that ComponentType is used in JSDoc and hence will not flag it as unused; TS-ESLint, on the other hand, reports @typescript-eslint/no-unused-vars, because it's unaware of JSDoc.

ESLint offers the markVariableAsUsed API that we can leverage to mark this type as used. eslint-plugin-react takes advantage of this to mark React as used when there's JSX. I don't know if it's portable to types, but hopefully it is.

Current behavior

Reports error.

Desired behavior

Should not give @typescript-eslint/no-unused-vars

Alternatives considered

This could also be an extension in TS-ESLint, but AFAIK they never handle JSDoc, so I decided to see if you would consider it first.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions