Subscribe on changes!

.tsx type inference for component's emit option type

avatar
Jan 25th 2021

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

avatar
Jan 26th 2021

#3096 implementation of this with TS feature of LibraryManagedAttributes & Template Type, it needs ts v4.1

avatar
Jan 26th 2021

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

avatar
Jan 26th 2021

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

avatar
Jan 26th 2021

I'm working on something very similar (#2164) but for the defineComponent and h, 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} ?

avatar
Jan 26th 2021

u mean u are not sure that it can map vue emit name XXX to JSX attr onXXX={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)

avatar
Jan 26th 2021

#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.

avatar
Nov 3rd 2023

Closing as it's working on the latest main. image