language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

TS/JS docs get lost when using $$restProps

Open mrtnbroder opened this issue 4 years ago • 2 comments

Describe the bug When using {...$$restProps}, type infos are getting lost when running svelte-kit package

To Reproduce repro to clone: https://github.com/mrtnbroder/svelte-lost-types

Expected behavior Using $$restProps shouldn't mess up the types produced

When using $$restProps

import { SvelteComponentTyped } from "svelte";
declare const __propDef: {
    props: {
        [x: string]: any;
        class?: string | null;
        disabled?: boolean | null;
    };
    events: {
        [evt: string]: CustomEvent<any>;
    };
    slots: {
        default: {};
    };
};
export declare type ButtonProps = typeof __propDef.props;
export declare type ButtonEvents = typeof __propDef.events;
export declare type ButtonSlots = typeof __propDef.slots;
export default class Button extends SvelteComponentTyped<ButtonProps, ButtonEvents, ButtonSlots> {
}
export {};

vs

not using $$restProps

import { SvelteComponentTyped } from "svelte";
declare const __propDef: {
    props: {
        /** CSS class for the element. */ class?: string | null;
        /** Whether the button is disabled. */ disabled?: boolean | null;
    };
    events: {
        [evt: string]: CustomEvent<any>;
    };
    slots: {
        default: {};
    };
};
export declare type ButtonProps = typeof __propDef.props;
export declare type ButtonEvents = typeof __propDef.events;
export declare type ButtonSlots = typeof __propDef.slots;
export default class Button extends SvelteComponentTyped<ButtonProps, ButtonEvents, ButtonSlots> {
}
export {};

mrtnbroder avatar Feb 08 '22 15:02 mrtnbroder

To me this looks as expected. You are using $$restProps which means you support passing other properties than the ones explicitly defined on the component. So the type definitions need to reflect that by also having an index signature on the props definition. Is it this what you think is wrong or is it something else?

dummdidumm avatar Feb 08 '22 15:02 dummdidumm

@dummdidumm I'm talking about the comments here -> ** CSS class for the element. *

mrtnbroder avatar Feb 08 '22 15:02 mrtnbroder