Function: extractEmitsFromComponentCtor()
ts
function extractEmitsFromComponentCtor<T>(
component: T,
): ExtractEmitValidatorsFromComponent<T>;Extracts emit validators from a Vue component's emits definition. Supports both array format (event names only) and object format (with validators).
Type Parameters
| Type Parameter | Description |
|---|---|
T extends { emits?: any; } | The component type |
Parameters
| Parameter | Type | Description |
|---|---|---|
component | T | A Vue component with an emits definition |
Returns
ExtractEmitValidatorsFromComponent<T>
An EmitValidators object with event names and their validators
Example
typescript
const MyComponent = defineComponent({
emits: {
"update:modelValue": (val: string) => typeof val === "string",
close: () => true,
},
});
const validators = extractEmitsFromComponentCtor(MyComponent);
// validators['update:modelValue'](123) // false
// validators['update:modelValue']('hello') // true