Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using decorators on class reports class is declared but never used

See original GitHub issue

Bug Report

🔎 Search Terms

“decorator unused” “decorator declared but never used”

🕗 Version & Regression Information

  • I was unable to test this on prior versions because my project relies on auto-accessor which is only available since ts 4.9

⏯ Playground Link

Playground link with relevant code

💻 Code

function defineElement(name: string): any {

class MyElement extends HTMLElement {


🙁 Actual behavior

TypeScript reports 'MyElement' is declared but never used..

And If I click “Quick Fix” in vscode, it removes my entire class declaration and decorator call.

🙂 Expected behavior

No error reports.

Issue Analytics

  • State:open
  • Created 9 months ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

fatcerberuscommented, Dec 22, 2022

It’s admittedly kind of a gray area, the class is only “used” in the same sense that let x = 0; x++; “uses” x. Having decorators with non-local (to the class) side effects feels like an anti-pattern. You don’t “decorate” a Christmas tree by adding more furniture to the room around it…

MartinJohnscommented, Dec 22, 2022

I think it would be much better to either ignore the error, export the class or use it in an empty dummy function than to make this not an error. I believe in the majority of cases this legitimately considered unused.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why `Error:(3, 1) TS1238:Unable to resolve signature of class ...
Here is how class and property decorators are declared in lib.d.ts : declare type ClassDecorator = <TFunction extends Function>( ...
Read more >
Primer on Python Decorators
In this introductory tutorial, we'll look at what Python decorators are and how to create and use them.
Read more >
Documentation - Decorators - TypeScript
A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use...
Read more >
Decorators do not work as you might expect
The claim was that decorators are not instance-targeted and only called once per class and usage. To proof this, we'll implement our own ......
Read more >
Python: Decorators in OOP - Towards Data Science
We'll see three popular decorators used in classes and their ... (using the get_percent method) and generates a report as a string with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found