Subscribe on changes!

TSX Wrong Emit Handler Return Type

avatar
Aug 10th 2021

Version

3.2.1

Reproduction link

https://jsfiddle.net/986ukynp/

Steps to reproduce

Event handler should return void not validation value of emit.

What is expected?

No type error

What is actually happening?

Type error is happening

image

avatar
Aug 10th 2021

@webfansplz I edited type code with your pull request and nothing changed. The problem is here I think. image

I don't have a good knowledge about typing types but if I change it to this, I don't get any type error in component file but in type file. image image

avatar
Aug 10th 2021

Hi @kadiryazici,Maybe you just forgot to return it when you invoked it

import { defineComponent } from 'vue';


const Component = defineComponent({
   emits: {
      something: (value: string) => true
   }
});

const OtherComponent = defineComponent({
   render() {
      return (
         <Component
            onSomething={() => {
               console.log('yeah');
               return true  // return true
            }}
         />
      );
   }
});

export default OtherComponent
avatar
Aug 10th 2021

@webfansplz it is not the return type of emit, it is just validator. I return true from validator because I don't need validaton. Vscode type checking is enough for me.

Emit handler should return any or void always.

avatar
Aug 10th 2021

@kadiryazici You are right, I have mentioned PR to fix this