🐾
优化 tsconfig 配置

React 项目中的 TypeScript 类型是由 @types/react (opens in a new tab)@types/react-dom (opens in a new tab) 这两个包提供的。

TS 配置文件 tsconfig.json (opens in a new tab) 中你总会看到 jsxlib 这两个配置项。

{
  "compilerOptions": {
    "jsx": "preserve",
    "lib": ["ESNext", "DOM"]
  }
}

lib 表示你要引入的类型文件。比如 ["ESNext", "DOM"] 表示引入最新版 ECMAScript 类型定义和浏览器 DOM 相关的类型定义。

jsx 表示 tsx 文件的处理方式。"preserve" 表示将 tsx 文件编译成 jsx 文件并保留 JSX 语法。JSX 后续会被 babel 处理。 测试 tsx 其他编译结果 (opens in a new tab)


MIT 2024 © Binghuis