tsconfig 分治策略
如何通过分治策略来管理 Monorepo 项目中的多个 tsconfig 文件,以实现更好的类型安全和项目结构?
原文只保留到「安装 Vites」一节,后续内容尚未迁移。
这是一个非常简单的前端应用程序,创建一个段落元素并向其中写入欢迎文本。
// src/app.ts
const greetingText = document.createElement("p")
greetingText.innerText = "Hello, John!"
document.body.appendChild(greetingText)tsx但是,有个问题, document 从哪里来的?你可以说它是 JavaScript 中的全局变量,你说得对。
但这是 TypeScript 代码,它必须被编译成 JS,才能让浏览器向它公开 document 全局变量。
那么 TypeScript 是如何知道 document 的存在及其方法呢?
TypeScript 通过加载一个默认的定义库叫做 lib.dom 来做到这一点。(就是一个包含一堆类型的.d.ts文件,用来描述 JavaScript 全局变量。)
接下来,安装 Vites,编写一段测试代码:
// src/app.test.ts
it("greets John", async () => {tsx