vue-ts-utils
v0.2.3
Published
Typescript utils for Vue2 and Vue3
Downloads
37
Readme
Vue TS Utils
Typescript utils for vue2 and Vue3
Installation
npm install vue-ts-utils -D
Features
Inferring Attrs
- Option Component
const Comp = defineComponent({
slots: Object as SlotsType<{
foo?: { data: string }
}>,
attrs: Object as AttrsType<{
bar?: string
}>,
setup(props, { slots, attrs }) {
console.log(attrs.bar)
slots.foo?.({ data: 'a' })
}
});
<Comp bar={"str"} />;
- Functional Component
const Comp = defineComponent(
(props: { foo: string }, ctx) => {
console.log(ctx.attrs.bar)
return () => (
<div>{props.foo}</div>
)
},
{
slots: Object as SlotsType<{
baz?: { data: string }
}>,
attrs: Object as AttrsType<{
bar?: number
}>
}
);
<Comp bar={1} foo={"str"} />;