Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally rendering nothing on an aria attribute produces an error when it shouldn't #316

Open
mark-dropbear opened this issue Jul 26, 2023 · 2 comments · Fixed by JackRobards/lit-analyzer#107 · May be fixed by #364

Comments

@mark-dropbear
Copy link

The code below is an example taken from an element class that demonstrates a scenario that triggers the following error on the aria-current attribute for the link element.

Type '"page" | Symbol(undefined)' is not assignable to '"page" | "step" | "location" | "date" | "time" | "true" | "false"'lit-plugin(no-incompatible-type-binding)(2304)

#renderLinks(): TemplateResult {
  return html`
    <ul>
      ${this.#menuItems.map((link) => {
      return html`
        <li>
          <a href="${link.href.pathname}" aria-current="${this.#isCurrentPage(link.href) || nothing }">${link.text}</a>
        </li>
      `})
    }
    </ul>
  `;
}

#isCurrentPage(url: URL){
  if(url.pathname === window.location.pathname){
    return 'page';
  } else {
    return undefined;
  }
}

This should not trigger an error as per these guidelines: https://lit.dev/docs/templates/conditionals/#conditionally-rendering-nothing

@dairiki
Copy link

dairiki commented Sep 17, 2023

Possible dup of #251

SegaraRai added a commit to SegaraRai/lit-analyzer that referenced this issue Jul 27, 2024
@SegaraRai SegaraRai linked a pull request Jul 27, 2024 that will close this issue
@TazmanianDI
Copy link

TazmanianDI commented Jan 6, 2025

FYI, the way I got around this was to use (nothing as any). That seems to suppress the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants