Skip to content

ESlint false positive with custom component. #194

@ptrxyz

Description

@ptrxyz

ESlint somehow reports an unsafe-member-access error when I try to access a exported property of a componente. Consider this component:

<script lang="ts">
    // comp.svelte
    export const value1 = 3
    export const api = {
        value2: 3,
        get value3() {
            return 1
        },
    }
</script>

which is imported here:

<script lang="ts">
    // +page.svelte
    import Comp from 'comp.svelte'

    let x: Comp

    $: if (x) console.log(x.value1, x.api.value2, x.api.value3, x.something)
</script>

<Comp bind:this={x} />

If I run svelte-kit sync; pnpm lint I get an error:

/tmp/eslint-test/src/routes/+page.svelte
  6:37  error  Unsafe member access .value2 on an `any` value  @typescript-eslint/no-unsafe-member-access
  6:51  error  Unsafe member access .value3 on an `any` value  @typescript-eslint/no-unsafe-member-access

However api is actually typed. Typescript also doesn't seem to complain:

image

Does anyone know what's going wrong here?

--
A minimal example based on the SvelteKit template can be found here:
Github-Repo
StackBlitz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions