将 @query 与 LitElement 和 Typescript 结合使用

Using @query with LitElement and Typescript

我正在尝试这样做:

@query('#gist')
gist: HTMLIFrameElement;

打字稿 linting 说:

Property 'gist' has no initializer and is not definitely assigned in the constructor.

我们如何清除它?

您可以在 属性 名称后使用 !。这告诉 Typescript 该值将被设置。

@query('#gist')
gist!: HTMLIFrameElement|null;