.tsx type inference for component's emit option type
What problem does this feature solve?
const Hello = defineComponent({
emits: ['cancel'],
render() {
return <div onClick={() => this.$emit('cancel')}>cancel me</div>
}
});
// now vue can't support infer the emit option of component to tsx attr
<Hello onCancel={() => console.log('it works')} />
What does the proposed API look like?
achive the inference to emit option of component in tsx attr
#3096 implementation of this with TS feature of LibraryManagedAttributes
& Template Type
, it needs ts v4.1
Has @pikax ever worked for this? maybe @pikax can give https://github.com/vuejs/vue-next/pull/3096 a review. I think it may not be necessary to use LibraryManagedAttributes
? because it can work like props
I'm working on something very similar (https://github.com/vuejs/vue-next/pull/2164) but for the defineComponent
and h
, but sure if that would translate for the TSX
I'm working on something very similar (#2164) but for the
defineComponent
andh
, but sure if that would translate for the TSX
u mean u are not sure that it can map vue emit name XXX
to JSX attr onXXX={xxx}
?
u mean u are not sure that it can map vue emit name
XXX
to JSX attronXXX={xxx}
?
No, I meant if the https://github.com/vuejs/vue-next/pull/2164 would work on TSX (I just tested and it doesn't)
We should be using a very similar approach not sure if we can reuse the same types, the types I created are here you if could review and give your opinion would be good :)
We will also need test on your changes (also on my PR)
#2164 just resolves component's inner type inference but no TSX attr inference.
if we want to resolve it, we must to do some change to global JSX namespace
, and use some feature of it to resovle this.