Giter Club home page Giter Club logo

Comments (2)

qmhc avatar qmhc commented on June 14, 2024 1

defineEmits 使用 ts 的形式只能定义返回值 emit 的类型,想要定义对外事件的类型目前只能用过用 js 的方法传入一个验证对象:

const emit = defineEmits({
  // 该函数的入参和事件完全一样,vue 内部会通过 infer 获取参数类型并赋值给 onAdd
  add: (vaule: number) => true
})

最后会得到事件类型声明如下:

{
  onAdd?: ((value: number) => any) | undefined
}

from vite-plugin-dts.

x-255 avatar x-255 commented on June 14, 2024

defineEmits使用ts的类型定义只能使用过一次的返回值emit事件的当前类型,定义一个唯一的类型js验证对象:

const  emit  =  defineEmits (函数的函数和事件完全一样,vue 会通过 infer 获取类型参数输入并给定参数onAdd 
  add : number ) = > true } )
    

最后会发生的事件类型声明如下:

{ 
  onAdd ?: ( (: number )  =>  any )  |  未定义
}

有用,谢谢老哥

from vite-plugin-dts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.