Skip to content

Typescript doesn't catch using nonexistent fields on refsΒ #8210

@erezarnon

Description

@erezarnon

Describe the bug

When using refs gotten through bind:this, typescript doesn't alert you if you access properties that don't exist. I'm guessing it's because interface SvelteComponentDev has [accessor: string]: any.

Reproduction

// ComponentA.svelte
<script lang="ts">
  export function log() {
    console.log(5)
  }
<script>

<div>hello</div>

// ComponentB.svelte
<script lang="ts">
  import ComponentA from './ComponentA';

  let componentARef: ComponentA;

  onMount(() => {
    componentARef.logWithTypo(); // should error
  })
<script>

<ComponentA bind:this={componentARef} />

Logs

No response

System Info

System:
    OS: Linux 5.19 Ubuntu 22.10 22.10 (Kinetic Kudu)
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-1260P
    Memory: 5.46 GB / 15.33 GB
    Container: Yes
    Shell: 5.2.2 - /bin/bash
  Binaries:
    Node: 18.7.0 - /tmp/xfs-bd4c206b/node
    Yarn: 3.3.0 - /tmp/xfs-bd4c206b/yarn
    npm: 8.18.0 - /usr/bin/npm
  Browsers:
    Chrome: 109.0.5414.74
    Firefox: 109.0

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions