Skip to content

Incorrect type generation for components without script tag #1112

@bluwy

Description

@bluwy

Describe the bug
If a component doesn't have a script tag or has nothing in a script tag, the generated type class doesn't extend from SvelteComponentTyped. This causes the vscode extension to complain "cannot be used as JSX component" (Screenshot below).

To Reproduce
Steps to reproduce the behavior:

I'm using svelte2tsx emitDts() to generate the types.

Given: Section.svelte

<section class="my-6">
	<slot />
</section>

Output:: Section.svelte.d.ts

/** @typedef {typeof __propDef.props}  SectionProps */
/** @typedef {typeof __propDef.events}  SectionEvents */
/** @typedef {typeof __propDef.slots}  SectionSlots */
export default class Section {
}
export type SectionProps = typeof __propDef.props;
export type SectionEvents = typeof __propDef.events;
export type SectionSlots = typeof __propDef.slots;
declare const __propDef: {
    props: {};
    events: {
        [evt: string]: CustomEvent<any>;
    };
    slots: {
        default: {};
    };
};
export {};

Expected behavior

/** @typedef {typeof __propDef.props}  SectionProps */
/** @typedef {typeof __propDef.events}  SectionEvents */
/** @typedef {typeof __propDef.slots}  SectionSlots */
- export default class Section {
+ export default class Section extends SvelteComponentTyped<{
+ }, {
+  ​[evt: string]: CustomEvent<any>;
+ }, {
+  default: {};
​+ }> {
}
export type SectionProps = typeof __propDef.props;
export type SectionEvents = typeof __propDef.events;
export type SectionSlots = typeof __propDef.slots;
+ import { SvelteComponentTyped } from "svelte";
declare const __propDef: {
    props: {};
    events: {
        [evt: string]: CustomEvent<any>;
    };
    slots: {
        default: {};
    };
};
export {};

Screenshots
Screenshot from 2021-07-23 15-23-24

System (please complete the following information):

  • OS: Ubuntu 21.04
  • IDE:VSCode
  • Plugin/Package: svelte2tsx

Additional context
I'm able to reproduce with local repo of language-tools. Trying to figure out why.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedFixed in master branch. Pending production release.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions