vue+ts使用中遇到的问题

想请教一下大家下面两个问题。

1、下面第二个路由对象报:不能将类型“{ path: string; redirect: string; component: () => Promise<typeof import("*.vue")>; }”分配给类型“RouteRecordRaw”。 类型 "{ path: string; redirect: string; component: () => Promise*.vue")>; }" 中缺少属性 "children",但类型 "RouteRecordSingleViewWithChildren" 中需要该属性。ts(2322)
const routes: Array =  [
  {
    path: '/home',
    name:'home',
    component: () => import('@/views/test/Test.vue')
  },
  {
    path: '/',
    redirect:'/login',
    component: () => import('@/views/login/Login.vue')
  },

2.


下面proxy?.$md5中的$md5报:类型“ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string>, {}>”上不存在属性“$md5”。

// main.ts
import md5 from 'md5.js'
const app = createApp(App)
app.config.globalProperties.$md5 = new md5()

//Login.vue
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
function clickme() {
    // console.log(new md5().update('42').digest('hex'))
    proxy?.$md5.update('42').digest('hex')
}

“Devil组”引证GPT后的撰写:
1.错误信息提示在第二个路由对象中缺少 "children" 属性。 "children" 是用于定义子路由的属性,如果你不需要定义子路由,可以在对象中加上一个空的 "children" 数组作为占位符即可,例如:

const routes: Array<RouteRecordRaw> =  [
  {
    path: '/home',
    name:'home',
    component: () => import('@/views/test/Test.vue')
  },
  {
    path: '/',
    redirect:'/login',
    component: () => import('@/views/login/Login.vue'),
    children: [] // 添加空的 "children" 属性
  }
]


2.错误信息提示在 ComponentPublicInstance 类型中不存在 "$md5" 属性。这是因为 "$md5" 是在 app.config.globalProperties 中添加的全局属性,ComponentPublicInstance 类型并没有包含这个属性。你需要在类型断言之后,使用类型 "any" 来跳过类型检查,例如:

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
function clickme() {
  (proxy as any)?.$md5.update('42').digest('hex')
}


这种写法会跳过类型检查,如果你确定 $md5 属性一定存在,可以这样写,但是建议在定义组件的时候,也要将 $md5 属性加入到组件类型定义中,这样能够更好的避免类型错误。