简体   繁体   English

未选择 tsconfig.json typeroots 自定义路径

[英]tsconfig.json typeroots custom path not picked up

I have some custom .d.ts files and I want tsc to pick up these files when compiling.我有一些自定义的 .d.ts 文件,我希望 tsc 在编译时选择这些文件。 In order to get this done I modify the tsconfig.file to include the following为了完成这项工作,我修改了 tsconfig.file 以包含以下内容

"typeRoots": [
      "../node_modules/@types",
      "./app/modules"
    ]

./app/modules is where my custom .d.ts file resides. ./app/modules 是我的自定义 .d.ts 文件所在的位置。 Inside the ./app/modules folder I have the following file myModule.d.ts在 ./app/modules 文件夹中,我有以下文件 myModule.d.ts

export declare module myModule {
  function Login();
  function Logout();
}

Now inside my other typescript file I have the following import现在在我的其他打字稿文件中,我有以下导入

import { myModule } from 'myModule';

Here I get the following error Cannot find module 'myModule'.在这里,我收到以下错误找不到模块“myModule”。

I found the config that fixes this.我找到了解决这个问题的配置。 Note the paths and baseUrl properties:注意pathsbaseUrl属性:

{
  "version": "2.1.5",
  "compilerOptions": {
    "module": "commonjs",
    "target": "ES5",
    "removeComments": true,
    "preserveConstEnums": true,
    "inlineSourceMap": true,
    "lib": ["es6", "dom"],
    "typeRoots": ["src/subfolder/node_modules/@types"],
    "moduleResolution": "node",
    "baseUrl": "./",
    "paths": {
      "*": ["src/subfolder/node_modules/@types/*", "*"]
    }
  },
  "exclude": ["node_modules", "src/subfolder/node_modules"]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM