Skip to content

Conversation

buqiyuan
Copy link
Contributor

example:

props.ts:

export const formEmits: ObjectEmitsOptions = {
    submit: (values) => isObject(values)
}

export type FormEmits = typeof formEmits;

Form.vue:

<script setup lang="ts">
import { formEmits } from './props' 

const emit = defineEmits(formEmits)

const { handleSubmit } = useFormEvents({ emit })
</script>

useFormEvents.ts

import type { EmitFn } from 'vue'
import type { FormEmits } from './props'

type UseFormEventParams = {
   emit: EmitFn<FormEmits>
}

export const useFormEvents({ emit }: UseFormEventParams) {
  const handleSubmit = (values) => {
      // type check / auto-completion
      emit('submit', values) 
  }
  
  return {
      handleSubmit
  }
}

@buqiyuan buqiyuan changed the title types(runtime-core): export some types types(runtime-core): export emit types May 26, 2024
Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 90.8 kB 34.5 kB 31.1 kB
vue.global.prod.js 148 kB 53.7 kB 48 kB

Usages

Name Size Gzip Brotli
createApp 50.8 kB 19.9 kB 18.1 kB
createSSRApp 54.1 kB 21.2 kB 19.3 kB
defineCustomElement 53.1 kB 20.6 kB 18.8 kB
overall 64.6 kB 24.9 kB 22.6 kB

@haoqunjiang haoqunjiang added scope: types version: minor 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. labels May 27, 2024
@yyx990803 yyx990803 changed the title types(runtime-core): export emit types feat(types): export emit types May 30, 2024
@yyx990803 yyx990803 changed the base branch from main to minor May 30, 2024 03:10
@yyx990803 yyx990803 merged commit 189573d into vuejs:minor May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. scope: types version: minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants