Feature Request: support generic emits
See original GitHub issue<script lang="ts">
declare const Bar: new <T>(props: { readonly value: T }) => {
$props: typeof props;
$emit: {
(event: "update:value", e: T): void;
};
};
const console = window.console;
</script>
<script setup lang="ts">
</script>
<template>
<div id="app">
<Bar :value="1" @update:value="console.log($event)" />
</div>
</template>
The type of $event
should be number
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Feature request response email templates - LiveAgent
Feature requests are messages that customers send to inquire about a feature that is not included in your product or service. Receiving feature...
Read more >Feature Requests: What are they and how to manage them
Feature requests are a form of product feedback you may frequently encounter as a SaaS product manager. They typically come in the form...
Read more >The right way to respond to feature requests - Inside Intercom
It's easy to respond to these feature requests with a generic “Keep an eye on Twitter for updates” response or a pre-canned “We'll...
Read more >10 Tips to Improve Your Feature Request Responses - Nicereply
Feature requests are the best way to improve your product. Here are ten tips to make the most out of them.
Read more >Documentation - Decorators - TypeScript
A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@xiaoxiangmoe okay thank you. For now I found an acceptable solution, which looks like this:
The result is that any slot whose name is one of the
column_options
, I will get the exact type that I want, namely this:And any slot whose name is not one of the
column_options
, I will get nearly the exact type I want:Like it would’ve been nice if
column
had still been"quantityyyyy"
, but this is already miles better than what I got before. Because when I asked you the question a few days ago,data
was just alwaysany
.But anyhow, I actually wanted to ask you one more question. I hope I’m not asking too much.
In your example, and also in my code, you are giving the
Bar
component its type definition from within another component; from within the component that’s using theBar
component. Do you know if it’s possible to give theBar
component its type definition from within theBar
component itself?I know it’s possible to define an
export type
insideBar.vue
, but then in every component where you want to useBar
, you’d need to do something like this:I’m hoping there’s a more elegant solution, where I can just
import Bar from "./Bar.vue"
and by simply using it like your example:<Bar :value="1" @update:value="console.log($event)" />
, the type of$event
is implied through the generics.Do you know a way to do that from within
Bar.vue
?In vue 2:
In vue 3:
change $scopedSlots to $slots