-
-
Notifications
You must be signed in to change notification settings - Fork 487
Closed
Labels
Description
When you want to infer props from a base component, volar currently can't infer the props
types (vuedx
currently works)
This code works in typescript
const TestBase = defineComponent({
props: {
show: Boolean,
title: String,
},
});
type TestBaseType = typeof TestBase extends DefineComponent<
infer Props,
any,
any,
any,
any,
any,
any,
any
>
? Props
: {};
const Child = defineComponent({
props: {
// props contains the props options
...(TestBase.props as TestBaseType),
extra: String,
},
setup(props) {
let i: boolean = props.show; // boolean
},
});
But as soon as you separate into SFC types, the type gets lost:
// test.vue
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
props: {
show: Boolean,
title: String,
},
});
</script>
// Child.vue
<script lang="ts">
import { defineComponent } from 'vue';
import TestBase from './test.vue'
type TestBaseType = typeof TestBase extends DefineComponent<
infer Props,
any,
any,
any,
any,
any,
any,
any
>
? Props
: {};
export default defineComponent({
props: {
// props contains the props options
...(TestBase.props as TestBaseType),
extra: String,
},
setup(props) {
// does not work beacuse TestBaseType will be `{}`
let i: boolean = props.show; // boolean
},
});
</script>
Muromi-Rikka, odex21, johnsusek, mwahlhuetter and sadeghbarati