youzan / vant

A lightweight, customizable Vue UI library for mobile web apps.
https://vant.pro/vant/
MIT License
23.21k stars 9.49k forks source link

[Bug Report] .vue + ts 编写组件模式,编译错误 #12912

Open beliefgp opened 4 months ago

beliefgp commented 4 months ago

重现链接

https://gitee.com/cyxwmm/vant-cli-test

Vant 版本

7.0.0

描述一下你遇到的问题。

在以 ts + .vue 模式开发组件时,就会出现 ts 类型编译问题,主要是 cli 的执行顺序导致。

比如组件含有连个文件 input.vue 和入口文件 index.ts:

import Input From './input.vue';

export { Input }

按现在 cli 的逻辑: 先执行 TS 声明编译:代码 这里会先 .vue 文件的预编译:代码

那么现在项目文件变成了:input.tsindex.ts。 此时 index.ts 里的内容未做任何改变,再执行 tsc 时,import Input From './input.vue'; 这句代码将无法编译,因为 input.vue 已经被改成了 index.ts

虽然后续编译 ts 文件时有对 .vue 等文件后缀处理 代码,但时机已经晚了。

这里可能需要调整处理后缀逻辑的运行时机。

重现步骤

vant-cli build

设备/浏览器

No response

github-actions[bot] commented 3 months ago

Hello @beliefgp. We totally like your proposal/feedback, welcome to send us a Pull Request for it. Please send your Pull Request to main branch, provide changelog/TypeScript/documentation/test cases if needed and make sure CI passed, we will review it soon. We appreciate your effort in advance and looking forward to your contribution!

你好 @beliefgp,我们完全同意你的提议/反馈,欢迎直接在此仓库 创建一个 Pull Request 来解决这个问题。请将 Pull Request 发到 main 分支,提供改动所需相应的 changelog、TypeScript 定义、测试用例、文档等,并确保 CI 通过,我们会尽快进行 Review,提前感谢和期待你的贡献。