Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(svelte): strongly type dispatched events #1703

Merged

Conversation

metonym
Copy link
Contributor

@metonym metonym commented Dec 18, 2023

Currently, the TypeScript definitions for Svelte components are auto-generated by @sveltejs/package. However, the exact types for the dispatched events use any.

For example, they currently look like:

declare const __propDef: {
    props: {
        [x: string]: any;
        options: BarChartOptions;
        data: ChartTabularData;
        chart?: SimpleBarChartCore | null;
        ref?: HTMLDivElement | null;
    };
    events: {
        load: CustomEvent<any>;
        update: CustomEvent<any>;
        destroy: CustomEvent<any>;
    } & {
        [evt: string]: CustomEvent<any>;
    };
    slots: {};
};

The solution is to define the types for dispatched events, and pass it as a type variable to the generic createEventDispatcher.

To test this, I ran yarn build:package and inspected the generated types:

declare const __propDef: {
    props: {
        [x: string]: any;
        options: BarChartOptions;
        data: ChartTabularData;
        chart?: SimpleBarChartCore | null;
        ref?: HTMLDivElement | null;
    };
    events: {
        load: CustomEvent<null>;
        update: CustomEvent<{
            data: ChartTabularData;
            options: ChartOptions;
        }>;
        destroy: CustomEvent<null>;
    } & {
        [evt: string]: CustomEvent<any>;
    };
    slots: {};
};

Updates

  • fix(svelte): strongly type dispatched events

Demo screenshot or recording

@metonym metonym requested review from theiliad and a team as code owners December 18, 2023 01:59
Copy link

netlify bot commented Dec 18, 2023

Deploy Preview for carbon-charts-core ready!

Name Link
🔨 Latest commit 750e2b1
🔍 Latest deploy log https://app.netlify.com/sites/carbon-charts-core/deploys/657fa79391f0860008cd969b
😎 Deploy Preview https://deploy-preview-1703--carbon-charts-core.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 18, 2023

Deploy Preview for carbon-charts-react ready!

Name Link
🔨 Latest commit 750e2b1
🔍 Latest deploy log https://app.netlify.com/sites/carbon-charts-react/deploys/657fa7933b262b0008afa042
😎 Deploy Preview https://deploy-preview-1703--carbon-charts-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 18, 2023

Deploy Preview for carbon-charts-angular ready!

Name Link
🔨 Latest commit 750e2b1
🔍 Latest deploy log https://app.netlify.com/sites/carbon-charts-angular/deploys/657fa79385dd090008d81b07
😎 Deploy Preview https://deploy-preview-1703--carbon-charts-angular.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@nstuyvesant
Copy link
Contributor

@theiliad LGTM

@theiliad theiliad added type: bug 🐛 Something isn't working package: svelte labels Dec 18, 2023
@theiliad theiliad merged commit 1a37ef2 into carbon-design-system:master Dec 18, 2023
4 checks passed
@metonym metonym deleted the fix/svelte-event-types branch December 18, 2023 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: svelte type: bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants