我在构建期间在 vue typescript 中输入错误。
Type '{ [x: string]: any; name: string; parents: ...[]; id: string; createdAt: string; updatedAt: string; }[]' is not assignable to type 'Directory[]'.
Type '{ [x: string]: any; name: string; parents: ...[]; id: string; createdAt: string; updatedAt: string; }' is not assignable to type 'Directory'.
:directories="directories"
我的组件需要
Directory[]
作为道具:
export default defineComponent({
name: 'Directories',
components: {
DeleteDialog, EditDirectoryDialog, ContextMenu, DirectoryItem,
},
props: {
directories: {
type: Array as PropType<Directory[]>,
required: true,
},
}
我尝试像这样从另一个组件调用这个组件:
<Directories :directories="directories" />
数据看起来像这样:
data() {
directories: [] as Directory[],
};
这样调用组件没有报错:
<Directories :directories="directories as Directory[]" />