无法从另一个项目访问 Typescript 文件 - 项目参考

Shy*_*ikh 5 typescript angular

我正在尝试访问单一存储库中另一个项目中定义的类型。以下是项目的结构

-- packages
   -- project-a
      -- tsconfig.json
   -- project-b
      -- tsconfig.json
   -- shared
      -- src
         -- UserModel.ts
         -- index.ts
      -- tsconfig.json
   -- tsconfig.base.json
-- package.json
-- tsconfig.json (Default no changes here)
Run Code Online (Sandbox Code Playgroud)

tsconfig.base.json

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
      "declaration": true,
      "declarationMap": true,
      "emitDecoratorMetadata": true,
      "module": "commonjs",
      "noEmit": false,
      "composite": true
    },
    "files": [],
    "references": [{ "path": "./shared" }]
  }
Run Code Online (Sandbox Code Playgroud)

共享 tsconfig.json

{
  "extends": "../tsconfig.base.json",
  "compilerOptions": {
    "outDir": "lib",
    "baseUrl": "./",
    "rootDir": "src",
    "composite": true,
    "experimentalDecorators": true,
    "declaration": true,
    "declarationMap": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/__tests__/*", "**/__e2e__/*"]
}
Run Code Online (Sandbox Code Playgroud)

项目-a tsconfig.json

{
  "extends": "../tsconfig.base.json",
  "compileOnSave": true,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "downlevelIteration": true,
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "module": "es2020",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "jsx": "react", 
    "lib": [
      "es2018",
      "dom"
    ],
    "paths": {
      "@shared": ["../shared/src"]
    }

  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  },
  "references": [
    { "path": "../shared" }
  ]   
}
Run Code Online (Sandbox Code Playgroud)

即使在所有这些设置之后,当我尝试UserModel.tsproject-a 中的共享项目进行引用时,IDE 也无法识别UserModel.ts

项目-a中的导入行 import {UserModel} from '@shared/UserModel'; //Even tried 'shared/src/UserModel'

我该如何解决这个问题?

Onu*_*kır 0

请改变并尝试

项目-a tsconfig.json

    "paths": {
      "@shared/*": ["packages/shared/src/*", "packages/shared/src"]
    }
Run Code Online (Sandbox Code Playgroud)