runem / lit-analyzer

Monorepository for tools that analyze lit-html templates
MIT License
314 stars 35 forks source link

Allow setting directive to undefined #342

Open nmattia opened 6 months ago

nmattia commented 6 months ago

I often set a directive as potentially undefined:

`<hgroup
      ${shouldDoSomething ? ref(() => doSomething()) : undefined}
  >...</hgroup>
`

lit-analyzer flags this as incorrect:

    Type 'DirectiveResult<DirectiveClass> | undefined' is not a Lit 2 directive'
    ...
    no-incompatible-type-binding

is this use case really incorrect? In practice it seems that lit is happy with it and just drops the directive. This is much simpler than e.g. writing two different hgroups above (with only the directive being different between the two) and using one or the other.