Skip to content

Error with component typedef doesn't have event #1767

@jasonlyu123

Description

@jasonlyu123

Describe the bug

There'll be a type check error when the Component type definition extends SvelteCopmonentTyped<{}, {}, {}> in strict mode. Not sure if we should count it as a bug because it's possible to avoid it in the userland.

The error is

Argument of type 'typeof Component' is not assignable to parameter of type 'ConstructorOfATypedSvelteComponent'.
  Types of construct signatures are incompatible.
    Type 'new (options: IComponentOptions<{}>) => Component' is not assignable to type 'new (args: { target: any; props?: any; }) => ATypedSvelteComponent'.
      Construct signature return types 'Component' and 'ATypedSvelteComponent' are incompatible.
        The types of '$on' are incompatible between these types.
          Type '<K extends never>(type: K, callback: (e: {}[K]) => void) => () => void' is not assignable to type '(event: string, handler: ((e: any) => any) | null | undefined) => () => void'.
            Types of parameters 'callback' and 'handler' are incompatible.
              Type '((e: any) => any) | null | undefined' is not assignable to type '(e: never) => void'.
                Type 'undefined' is not assignable to type '(e: never) => void'.
...

Reproduction

<script lang="ts">
    import { SvelteComponentTyped } from "svelte";

    class Component extends SvelteComponentTyped<{}, {}, {}>{}
</script>

<Component></Component>

Expected behaviour

no error.

System Info

  • OS: Windows
  • IDE: VSCode

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions