项目中希望用 unplugin-auto-import/vite
插件将 /src/typings
目录下的类型挂载到全局
/src/typings/index.ts
代码
export type AccountListSearchInfo = {
page_size: number
page_number: number
keywords: string
status: string
type: string
user_name_list?: Array<string>
email: string
mobile: string
}
unplugin-auto-import/vite
配置
AutoImport({
dts: true,
imports: [
...,
{
from: '@/typings',
imports: ['AccountListSearchInfo'],
type: true,
}
]
})
生成的 auto-imports.d.ts
中类型如下
declare global {
// @ts-ignore
export type { Component, ComponentPublicInstance, ComputedRef, InjectionKey, PropType, Ref, VNode } from 'vue' // 自动导入的 vue 类型
// @ts-ignore
export type { RouteLocationRaw, RouteRecordRaw } from 'vue-router' // 自动导入的 vue-router 类型
// @ts-ignore
export type { AccountListSearchInfo } from '@/typings'
}
这时候问题来了,自动导入的 vue
和 vue-router
类型点击都能跳转,也有代码提示,但是我自定义的 typings
下面的类型无法跳转,且无提示
vue-router
有提示
typings
无提示
tsconfig.json
已配置
{
"compilerOptions": {
"baseUrl": "./",
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"moduleResolution": "Node",
"strict": true,
"jsx": "preserve",
"resolveJsonModule": true,
"isolatedModules": false,
"esModuleInterop": true,
"lib": ["ESNext", "DOM", "dom.iterable"],
"skipLibCheck": true,
"noEmit": true,
"types": ["node", "element-plus/global"],
"paths": {
"@/*": [
"src/*"
]
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/**/**/*.vue", "auto-imports.d.ts"],
"references": [{ "path": "./tsconfig.node.json" }]
}
不知道全局的类型导入怎么样才会有提示?