Skip to content

Instantly share code, notes, and snippets.

@naramdash
Created September 10, 2024 22:44
Show Gist options
  • Save naramdash/71511d034b577a3c82a2230666640fbd to your computer and use it in GitHub Desktop.
Save naramdash/71511d034b577a3c82a2230666640fbd to your computer and use it in GitHub Desktop.
how to add custom element vue template type support
import type { ComponentOptionsMixin, DefineComponent, PropType } from "vue";
import type {
Component,
ComponentAttributes, // Record<string, unknown>
ComponentEventMap // Record<string, CustomEvent>
} from "./component";
type Attrs = {
[P in keyof ComponentAttributes]: {
type: PropType<NonNullable<ComponentAttributes[P]>>;
required: true;
};
};
type Emits = {
[P in keyof ComponentEventMap]: (
event: ComponentEventMap[P],
) => void;
};
type ComponentVueType = DefineComponent<
Attrs,
Component,
unknown,
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
Emits
>;
declare module "vue" {
export interface GlobalComponents {
"my-component": ComponentVueType;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment