首页 > 解决方案 > 如何在 git 子模块中配置 tsconfig 文件?#forTsChecker

问题描述

我有这个项目,在这个项目中,我有一个 git 子模块作为共享组件,结构如下。

Porject
├─node_modules
├─src
│ ├─App
│ ├─common
│ │ ├─Components
├─CommonUI <== sub module
│ ├─.storybook
│ ├─node_modules
│ ├─src
│ │ ├─Components
│ ├─index.ts
│ └─tsconfig.json
├─tsconfig.json
├─webpack.config.js
└─typings

如果我在 git Shubmodule 中安装依赖项,主项目会出错。

输入 '{ onChange: (e: any) => void; 类型:字符串;检查:布尔值;类名:字符串;形式?:字符串 | 不明确的; 插槽?:字符串 | 不明确的; 样式:CSS 属性 | 不明确的; 标题?:字符串 | 不明确的; ... 274 更多 ...; 步骤?:字符串 | ... 1 更多 ... | 不明确的; }' 不可分配给类型 'DetailedHTMLProps<InputHTMLAttributes, HTMLInputElement>'。输入 '{ onChange: (e: any) => void; 类型:字符串;检查:布尔值;类名:字符串;形式?:字符串 | 不明确的; 插槽?:字符串 | 不明确的; 样式?: CSSProperties | 不明确的; 标题?:字符串 | 不明确的; ... 274 更多 ...; 步骤?:字符串 | ... 1 更多 ... | 不明确的; }' 不可分配给类型 'InputHTMLAttributes'。属性“样式”的类型不兼容。输入'import("MainProject/CommonUI/node_modules/@types/react/index")。CSS 属性 | undefined' 不可分配给类型 'React.CSSProperties | 不明确的'。

但是如果我在 git submodel 中删除 node_modules ,则不会出现此错误。我会很好地构建我的项目。

在主项目中 tsconfig.json 是这样的

{
  "ts-node": {
    "compilerOptions": {
      "module": "CommonJS"
    }
  },
  "compilerOptions": {
    "outDir": "./dist",
    "baseUrl": ".",
    "noImplicitAny": false,
    "target": "ESNext",
    "module": "ESNext",
    "noLib": false,
    "moduleResolution": "node",
    "sourceMap": true,
    "jsx": "react",
    "allowJs": true,
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "importsNotUsedAsValues": "preserve",
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "checkJs": false,
    "paths": {
      "@/*": ["./src/*"],
      "@Common/UI": ["gitSubmodule/src"]
    }
  },
  "exclude": ["node_modules", "dist"],
  "include": ["src/**/*", "typings", "SunglinkUI"]
}

这是 git 子模块中的 tsconfig 文件。

{
    "extends": "../tsconfig.json",
    "include": ["src/**/*"]
}

重点是为什么?为什么在我安装一些依赖项时删除 git 子模块中的 node_modules 可以但不行

标签: gitwebpacktsconfig

解决方案


推荐阅读