Skip to content

Type Alias: ExtractEmitValidatorsFromComponent<T>

ts
type ExtractEmitValidatorsFromComponent<T> = RemoveIndexSignature<
  T["emits"] extends readonly any[]
    ? ExtractEmitsFromArray<T["emits"]>
    : T["emits"] extends object
      ? ExtractEmitsFromObject<T["emits"]>
      : {} & GetComponentInstance<T> extends never
        ? {}
        : GetComponentProps<GetComponentInstance<T>> extends never
          ? {}
          : ExtractEmitsFromProps<GetComponentProps<GetComponentInstance<T>>>
>;

Extracts emit validators from a Vue component definition. This type utility examines both:

  1. The component's .emits property (array or object format)
  2. The component's prop types for event handlers (onEventName props)

And merges them into a single EmitValidators-compatible type.

Type Parameters

Type ParameterDescription
T extends { emits?: any; }The component type with optional emits property

Example

typescript
const MyComponent = defineComponent({
  props: {
    onUpdateModelValue: Function as PropType<(val: string) => void>,
  },
  emits: {
    close: () => true,
    submit: (data: any) => true,
  },
});

type Validators = ExtractEmitValidatorsFromComponent<typeof MyComponent>;
// Result: {
//   'update:modelValue': (val: string) => boolean
//   'close': () => boolean
//   'submit': (data: any) => boolean
// }