Search code examples
javascripttypescriptlit-element

Using @query with LitElement and Typescript


I'm trying to do this:

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

And the typescript linting says:

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

How do we clear this?


Solution

  • You can use a ! after the property name. This tells Typescript that the value will be set.

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