Guidance on TypeScript completions in Vue #1827
Unanswered
zzzachzzz
asked this question in
Ask For Help
Replies: 2 comments 3 replies
-
|
👀 looks like we're not currently generating the Vue types |
Beta Was this translation helpful? Give feedback.
3 replies
-
|
Here is Vue's own documentation for adding TypeScript support for Non-Vue Web Components. I have done something line this: import type { ConditionalKeys, SetFieldType } from 'type-fest';
import type { EmitFn, HTMLAttributes, PublicProps } from 'vue';
/**
* @see {@link https://vuejs.org/guide/extras/web-components.html#non-vue-web-components-and-typescript}
*/
export type DefineCustomElement<
ElementType extends HTMLElement,
Events extends EventMap = {},
SelectedAttributes extends keyof ElementType = keyof ElementType
> = new () => ElementType & {
/**
* @deprecated Do not use the $props property on a Custom Element ref, this is for template prop types only.
*/
$props: HTMLAttributes
& Partial<
// This allows attributes defined by WA as `number` to be defined as `string` in Vue templates.
// That is `<progress-bar value="10" />` instead of `<progress-bar :value="10" />`
SetFieldType<
Pick<ElementType, SelectedAttributes>,
ConditionalKeys<Pick<ElementType, SelectedAttributes>, number>,
number | string
>
>
& PublicProps;
/**
* @deprecated Do not use the $emit property on a Custom Element ref, this is for template prop types only.
*/
$emit: VueEmit<Events>;
};
type EventMap = {
[event: string]: Event;
}
type VueEmit<T extends EventMap> = EmitFn<{
[K in keyof T]: (event: T[K]) => void
}>;import type { DefineCustomElement } from './DefineCustomElement.js';
import type WaProgressBar from '@awesome.me/webawesome/dist/components/progress-bar/progress-bar.js';
declare module 'vue' {
interface GlobalComponents {
'wa-progress-bar': DefineCustomElement<
WaProgressBar,
{},
// You can add here all of the properties that the component lists on their doc page.
'value' | 'indeterminate' | 'label'
>;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I was messing around with both webawesome and shoelace, and had some difficulty getting the types setup, for two criteria to be fulfilled:
<wa-button>I was able to get autocompletion of global component names working by including this
web-awesome-globals.d.tsfile in my project'ssrc/directory:However, I don't get type checking of props/attributes.
Is this a known limitation, or just something undocumented? I only see react type defs in the webawesome dist, whereas in shoelace it also included vue types.
Beta Was this translation helpful? Give feedback.
All reactions