TS7016:TypeScript看不到普通的.js文件

时间:2019-03-07 11:00:29

标签: javascript typescript webpack

尝试从普通.js文件(JsModuleForStaticImport.js)导入一些变量时出现错误。类似的.ts加载没有错误。

TS7016: Could not find a declaration file for module './StaticallyImportedModules/JsModuleForStaticImport'.

enter image description here

我从最小的TS配置开始:

{
  "compilerOptions": {
    "target": "es6",
    "module": "ESNext",
    "strict": true
  }
}

JsModuleForStaticImport.js的包含内容:

const CONST_THAT_IMPORTED_BY_DEFAULT_FROM_STATIC_JS_MODULE =
   'I am const that imported by default from status JS module.';
export default CONST_THAT_IMPORTED_BY_DEFAULT_FROM_STATIC_JS_MODULE;

export const CONST_THAT_IMPORTED_FROM_STATIC_JS_MODULE =
   'I am const that imported (no by default) from status JS module.';

当然,Webpack配置中的resolve.extensions包括.ts.js

module.exports = [
  { 

    // ...

    resolve: {
      extensions: ['.ts', '.js']
  }
]

什么使我的配置不满意?

1 个答案:

答案 0 :(得分:1)

我认为您需要allowJs编译器选项:

{
  "compilerOptions": {
    "allowJs": "true",
    "target": "es6",
    "module": "ESNext",
    "strict": true
  }
}