首页 > 解决方案 > vue-router.d.ts(734, 5):预期的类型来自属性 'children',它在类型 'MyType' 上声明

问题描述

可以m在一级和二级使用,但是三级后提示错误

这个错误是关于的RouteRecordRaw,因为用自定义类型替换不会出现

在此处输入图像描述 在此处 输入图像描述

代码:

包.json

{
  "name": "bug-demo-type",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "vue-router": "^4.0.3"
  }
}

索引.ts

import { RouteRecordRaw } from 'vue-router';

type MyType = RouteRecordRaw & {
  m?: string;
  children?: Array<MyType>;
};

const ddd: Array<MyType> = [
  {
    path: '',
    redirect: '',
    children: [
      {
        m: '',
        path: '',
        redirect: '',
        children: [
          {
            m: '',
            path: '',
            redirect: '',
            children: [
              {
                path: '',
                redirect: '',
              },
            ],
          },
        ],
      },
    ],
  },
];

标签: typescriptvue-router

解决方案


推荐阅读