Created
September 10, 2024 22:44
-
-
Save naramdash/71511d034b577a3c82a2230666640fbd to your computer and use it in GitHub Desktop.
how to add custom element vue template type support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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