Skip to content

Bug: [no-unused-vars] Type-only imports reported as unused despite being referenced by JSDocs #11208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
Andarist opened this issue May 13, 2025 · 2 comments
Closed
4 tasks done
Labels
bug Something isn't working duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@Andarist
Copy link
Contributor

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.1.3&fileType=.tsx&code=MYewdgzgLgBNCuAzRMC8MDeAoGNEhAC4YByErAXyywHoAqOmAFQAsBLCGAQ2GAFMADlE4QQAWz5R2YAOYwANmwDWfTAAFFYJXChJEFGHRpY%2BADwEgATrETwwwKG3DdegqAGVdyABRdiGPAJiaEs2WRgKAEpMHBhLSXhLMG5KIA&eslintrc=N4KABGBECmAeAu0B2ATAzpAXGA2pADgDYCuA5gJZKYAC8AnvtGgMYBO5%2B8AtE4ZfAHpW0ZgHsAtuOQpoKSAF0wIAL5A&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

const stuff = {
  foo: ''
}

/** This accepts something like {@link stuff} */
export function acceptStuff(a: { foo: string }) {
  return a
}

ESLint Config

{
  "extends": ["plugin:@typescript-eslint/recommended"] 
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

I'd expect here stuff to be counted as used

Actual Result

An error is reported:

'stuff' is assigned a value but never used. 1:7 - 1:12

Additional Info

I'd like to make those cross-file @links to work without having to suppress the lint rule:
https://github.com/statelyai/xstate/blob/42bfd0a30d74e1c5820728220a00db692023f1f8/packages/core/src/createActor.ts#L815-L821

I want to avoid introducing runtime imports and import type { fromObservable } from "./actors/observable" etc would work here. But I get a lint error when using that.

@Andarist Andarist added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels May 13, 2025
@bradzacher
Copy link
Member

This is working as expected -- we do not support JSDoc references.

Duplicate of #10873, #9435, #8902, #5017, #6967, #7944, #8258

In particular the comment here: #8902 (comment)

You can use a rule such as jsdoc/no-undefined-types to mark the usages as variable usages.

@bradzacher bradzacher added duplicate This issue or pull request already exists and removed triage Waiting for team members to take a look labels May 13, 2025
@Andarist
Copy link
Contributor Author

Oh, I have not realized a different rule could mark something as used and that TS ESlint rule could not report this error based on that. Neat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants