Allowing to infer attrs by using attrs option of defineComponent or defineCustomElement.
And in the setup-script, passing generic type in the defineAttrs<T> will also infer attrs to T.
defineComponent
const Comp = defineComponent({
props: {
foo: String
},
attrs: Object as AttrsType<{
bar?: number
}>,
created() {
this.$attrs.bar // number | undefined
}
});
<Comp foo={'str'} bar={1} />;
Important: Do NOT comment on this PR. Please use the discussion thread linked above to provide feedback, as it provides branched discussions that are easier to follow.This also makes the edit history of the PR clearer.
Summary
Allowing to infer attrs by using
attrs
option ofdefineComponent
ordefineCustomElement
. And in thesetup-script
, passing generic type in thedefineAttrs<T>
will also inferattrs
toT
.defineComponent
Setup Script
Links
Important: Do NOT comment on this PR. Please use the discussion thread linked above to provide feedback, as it provides branched discussions that are easier to follow.This also makes the edit history of the PR clearer.