Search code examples
typescriptlit

Why doesn't TS know I am using @property from Lit?


I have the most basic Lit code like this:

import { property } from 'lit/decorators.js';

export class MyClass extends LitElement {
  @property()
  rows = [];
}

Outside of this sample, rows has data. My code renders as expected. However TS complains property is not being used? Is there some setup I may be missing around TS and decorators? I built the project using OWC.

image showing TS error in code


Solution

  • Seems Open WC is out of date. It installs typescript lint at 4.33.0 when it needs 5.*

    The general solution is listed here: Eslint wong error `is defined but never used` warning in NestJs for all decorators

    I updated the generated package.json to this:

    "@typescript-eslint/eslint-plugin": "^5.48.0",
    "@typescript-eslint/parser": "^5.48.0",
    

    I restarted my ESLint server in VS Code and everything worked fine.

    It was nearly immediately fixed via https://github.com/open-wc/open-wc/issues/2557 when I reported it.

    Leaving this question up for posterity.