Skip to content

@typescript-eslint/no-unsafe-member-access when checking if slot exsist #482

@mpiorowski

Description

@mpiorowski

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

8.40.0

What version of eslint-plugin-svelte are you using?

2.28.0

What did you do?

<script lang="ts">
    import LoadingComponent from "$lib/components/LoadingComponent.svelte";

    export let type: "button" | "submit" = "submit";
    export let loading = false;
    export let variant: "primary" | "secondary" | "error" = "primary";
    export let form: string | undefined = undefined;
    export let href = "";

    $: className =
        "w-full h-10 flex flex-row gap-3 justify-center items-center rounded px-4 shadow-md font-normal text-base text-white transition";
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    if (variant === "primary") {
        className += " bg-secondary-700 hover:bg-secondary-800";
    } else if (variant === "secondary") {
        className += " bg-primary-800 hover:bg-primary-900";
    } else if (variant === "error") {
        className += " bg-error-600";
    }
</script>

{#if href}
    <a {href} class={className}>
        <slot />
    </a>
{:else}
    <button {form} on:click {type} disabled={loading} class={className}>
        {#if loading}
            <div class="w-4 h-4 flex justify-center items-center">
                <LoadingComponent />
            </div>
        {:else if // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
        $$slots.icon}
            <div class="w-6 h-6 flex justify-center items-center">
                <slot name="icon" />
            </div>
        {/if}
        <slot />
    </button>
{/if}

What did you expect to happen?

No error when checking if slot exsist

What actually happened?

Missing eslint rule?

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/mpiorowski/rusve/blob/78bedb5dc4e491a53149a5476d8d711fa08347a7/client/src/lib/form/Button.svelte#L6

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions