我有以下VueJS组件(打字稿,vue-property-decorator):
import {PropType} from 'vue';
import {Component, Vue, Prop} from 'vue-property-decorator';
import {buildRouteLink, Route} from 'my-config';
@Component
export default class Report extends Vue {
// I've also tried Object as () => Route, which also doesn't work
@Prop({type: Object as PropType<Route>, required: true})
private route!: Route;
private url: string = '';
mounted() {
this.url = buildRouteLink(this.route);
}
}
问题是,如果我像这样安装组件:
<report :route="route"/>
并将route
属性传递为不符合Route
接口的类型(例如:{foo: true}
),我没有运行时验证错误,只有{ {1}},它期望存在buildRouteLink()
个字段。
Route
界面很简单:
Route
interface Route {
app: string;
route: string;
}
版本:3.2.4 typescript
版本:2.6.10 vue
版本:7.3.0