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

Bug: v-on emit type has no type #1023

Closed
xiaoxiangmoe opened this issue Mar 10, 2022 · 0 comments
Closed

Bug: v-on emit type has no type #1023

xiaoxiangmoe opened this issue Mar 10, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@xiaoxiangmoe
Copy link
Collaborator

xiaoxiangmoe commented Mar 10, 2022

<script lang="ts">
import { VNode } from 'vue';

declare const MyList: new <T>(props: { readonly dataSource: T[]; readonly 'onItem-click'?: (value: T) => void }) => {
    $props: typeof props;
    $scopedSlots: {
        default?: ({ data, index }: { readonly data: T; readonly index: number }) => VNode[] | undefined;
    };
};
const console = window.console;
</script>
<script setup lang="ts"></script>

<template>
    <MyList :data-source="[{ foo: 123, bar: false }]" @item-click="console.log($event)">
        <template #default="{ data, index }">
            <div>foo: {{ data.foo }}; index: {{ index }}</div>
        </template>
    </MyList>
</template>

The type of $event is any.

If we change 'onItem-click' to 'onItemClick', the type of $event will be { foo: number; bar: boolean; }.

Why?


Extra info:

https://v2.vuejs.org/v2/guide/components-custom-events.html

Unlike components and props, event names don’t provide any automatic case transformation.

@johnsoncodehk johnsoncodehk added the bug Something isn't working label Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants