尝试从普通.js
文件(JsModuleForStaticImport.js
)导入一些变量时出现错误。类似的.ts
加载没有错误。
TS7016: Could not find a declaration file for module './StaticallyImportedModules/JsModuleForStaticImport'.
我从最小的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']
}
]
什么使我的配置不满意?
答案 0 :(得分:1)
我认为您需要allowJs
编译器选项:
{
"compilerOptions": {
"allowJs": "true",
"target": "es6",
"module": "ESNext",
"strict": true
}
}