打字稿找不到自定义类型的定义文件

时间:2019-02-09 21:07:47

标签: typescript type-definition

我在tyepscript 3.3.3中使用VS Code 1.30.2。 tyepscript找不到位于src/@types中的自定义类型定义文件。尽管据我所知,不需要在ts的最新版本中配置typeRoot,但是我也这样做了,ts仍然找不到index.d.ts文件。文件夹名称和模块名称匹配。

.
├── config.ts
├── node_modules
├── ormconfig.json
├── package.json
├── project_manager
├── src
├── tsconfig.json
├── tslint.json
└── yarn.lock

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "lib": [ "es2015", "dom" ],
    "target": "es2015",                       
    "module": "commonjs",                     
    "resolveJsonModule": true,
    "allowJs": true,                          
    "jsx": "react",                                               
    "outDir": "./dist",                       
    "strict": true,                           
    "noImplicitAny": true,                    
    "noImplicitThis": true,                   
    "skipLibCheck": true,
    "noUnusedLocals": true,                   
    "noUnusedParameters": true,               
    "moduleResolution": "node",                                       
    "allowSyntheticDefaultImports": true,     
    "esModuleInterop": true,                  
    "experimentalDecorators": true,           
    "emitDecoratorMetadata": true,            
    "pretty": true,
  },
  "exclude": [
    "node_modules",
    "project_manager",
    "dist",
    "@types"
  ]
}

1 个答案:

答案 0 :(得分:0)

开始工作,就像是在魔咒恰到好处。在为最近的项目进行了一些挖掘之后,我在GitHub上发现了以下配置:

  1. 将您的$scope.editBusiness = function (business) { var ObjResolve = function () { return business; } $rootScope.OpenModal("BusinessTypesModal.html", "ModalInstanceCtrl", ObjResolve); }; 设置为baseUrl
  2. 为包含您的类型覆盖的目录添加.映射
  3. 为自定义类型创建paths文件

types-dir/module-name/index.d.ts的最小子部分如下所示:

tsconfig.json

在您的情况下,您可能希望{ "compilerOptions": { "baseUrl": ".", "outDir": "dist", "rootDir": "src", "paths": { "*": ["./types/*"] } } } 指向paths

相关问题