admin管理员组

文章数量:1122846

So I am having trouble with VS Code not recognizing the @ property decorator.

So I created the most basic Lit component.

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

class MyComponent extends LitElement {
  @property({ type: String }) myProperty = '';

  render() {
    return html`<div>${this.myProperty}</div>`;
  }
}

customElements.define('my-component', MyComponent);

But I still get a red line under property({ type: String }) and I can't figure out why. It seems to recognize property in the import because that doesn't have a red underline. I don't have red underlines for the imports. I am on typescript 5.7.2 and Lit 3.2.1. Since the most basic Lit example doesn't work I suspect my settings. I have these settings in my tsconfig as I was reading that may be relevent:

"compilerOptions": {
  "experimentalDecorators": true,
  "emitDecoratorMetadata": true,
  "target": "ES2020",
  "module": "ESNext",
  "moduleResolution": "Node"
}

I can pull up any webpack settings you may feel would be relevant.

I don't know what else could be causing it.

The error I get when hovering over "property" is below (I put it at the end since it is kind of long):

Unable to resolve signature of property decorator when called as an expression. No overload matches this call. Overload 1 of 3, '(target: ClassAccessorDecoratorTarget<MyComponent, string>, context: ClassAccessorDecoratorContext<MyComponent, string>): ClassAccessorDecoratorResult<...>', gave the following error. Argument of type 'undefined' is not assignable to parameter of type 'ClassAccessorDecoratorTarget<MyComponent, string>'. Overload 2 of 3, '(target: (value: string) => void, context: ClassSetterDecoratorContext<MyComponent, string>): (this: MyComponent, value: string) => void', gave the following error. Argument of type 'undefined' is not assignable to parameter of type '(value: string) => void'. Overload 3 of 3, '(protoOrDescriptor: Object, name: PropertyKey, descriptor?: PropertyDescriptor | undefined): any', gave the following error. Argument of type 'undefined' is not assignable to parameter of type 'Object'.ts(1240) Decorator function return type 'ClassAccessorDecoratorResult<MyComponent, string>' is not assignable to type 'void | ((this: MyComponent, value: string) => string)'.ts(1270)

本文标签: typescriptproperty not being recognized in LitStack Overflow