如何提供组件的规格?

问题描述

我正在使用 TypeScript 编写一个组件。

组件

@customElement("my-component")
export class MyComponent extends LitElement {

  @property({type: String}) myProperty = ""

  render() {
     return html`<p>my-component</p>`
  }
}

主要

// <!-- ... -->
<body>
  <my-component * ></my-component>
</body>

当我的光标位于星号 (*) 位置时,我的 IDE 是否可以提供 myProperty 属性

如果是,是否与组件的编写方式有关?我应该在别处添加规范吗?

还是仅与我的 IDE 相关?我将 LitElement 与 WebStorm 和 VSCode 一起使用,但它们都没有在键入时提供正确的自定义属性(我也在 VSCode 上使用了 lit-plugin)。

解决方法

我将 lit-pluginlit-html 与 VSCode 结合使用,这为我提供了您在 TypeScript 文件中描述的智能感知。

我发现我 had a lot of pain making sure TS could find the files 但一旦我解决了这个 lit-plugin 给了我非常可靠的智能感知和类型检查。