Bad derivation of type by `ExtractPropTypes`
mbarouski opened this issue · comments
Maksim Barouski commented
Issue description
Let's say we have interface:
interface InterfaceWithAllOptionalKeys {
a?: number;
b?: string;
}
then we use that interface to describe some property prop
of some component:
defineComponent({
props: {
prop: {
type: Object as PropType<InterfaceWithAllOptionalKeys>,
required: true
}
},
// ...
});
and as a result, the type of props.prop
inside setup(props)
function (for instance) is:
But if I change interface to:
interface InterfaceWithAllOptionalKeys {
a: number | undefined;
b?: string;
}
then the type of props.prop
is correct and is:
What's expected
To have type of props.prop
equal InterfaceWithAllOptionalKeys
for both interfaces.
How to reproduce
Code to reproduce the issue:
interface InterfaceWithAllOptionalKeys {
a?: number; // use `a: number | undefined;` to compare type of props.prop
b?: number;
}
defineComponent({
props: {
prop: {
type: Object as PropType<InterfaceWithAllOptionalKeys>,
required: true
}
},
setup(props) {
console.log(props.prop); // check type of props.prop in your IDE
}
});
github-actions commented
Stale issue message