Skip to content

自动导出的文件 imports.d.ts 中的语法导致 typescript 性能骤降 #617

@twtylkmrh

Description

@twtylkmrh

在一个 vite + vue3 + typescript 的项目中的

unplugin-auto-import: 21.0.0
typescript: 5.9.3

比如 unplugin-auto-import 自动导出的如下 imports.d.ts :

declare global {
  const Api: typeof import('@/api').Api
  const getUser: typeof import('@/api').getUser
}

在单文件形式下<script setup lang="ts">文件中 typescript 语法提示等功能的性能骤降。

如果把其中的 . 引用改为 [] 引用如下:

declare global {
  const Api: typeof import('@/api')['Api']
  const getUser: typeof import('@/api')['getUser']
}

typescript 语法提示等功能的性能就都恢复正常了。

tsconfig.js 是 vite 脚手架默认生成的。

这应该和 typescript 的解析机制有关于。

想问题的是 unplugin-auto-import 是否有配置项让其以 [] 引用方法导入方法。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions