首页 > 解决方案 > VSCode 在我的项目中找不到 TypeScript 模块和类型

问题描述

我有一个使用 TypeScript 的项目。它从命令行运行良好,但是当我在 VSCode 中打开它时,它抱怨无法找到各种模块和类型:

在此处输入图像描述 在此处输入图像描述

文件结构为:

- app/
  - javascript/
    - src/
      - app_reducer.ts
- spec/
  - javascript/
    - _test_helpers
      - factories.ts
- tsconfig.json
- tsconfig-test.json

此投诉来自一个文件factories.tstsconfig.json并且tsconfig-test.json是:

{
  "//": {
    "strictPropertyInitialization": true,
    "strict": true
  },
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "lib": ["es2017", "dom"],
    "module": "es6",
    "moduleResolution": "node",
    "alwaysStrict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "paths": {
      "src/*": ["app/javascript/src/*"]
    },
    "sourceMap": true,
    "strictNullChecks": true,
    "target": "es5",
    "jsx": "react"
  },
  "exclude": [
    "spec",
    "node_modules",
    "vendor",
    "public"
  ],
  "compileOnSave": false
}
{
  "compilerOptions": {
    "paths": {
      "src/*": ["app/javascript/src/*"],
      "_test_helpers/*": ["spec/javascript/_test_helpers/*"]
    }
  },
  "extends": "./tsconfig",
  "exclude": [
    "node_modules",
    "vendor",
    "public"
  ]
}

从命令行运行时它可以正常工作:

yarn tsc --noEmit -p tsconfig-test.json

标签: typescriptvisual-studio-code

解决方案


推荐阅读