以下是一个写在JS文件中的模块:
module.exports = {
propA: 1,
propB: 2
}
允许稍后从模块导入属性,例如:
import { propA } from 'path/to/module'
然而,将文件格式更改为TypeScript(如module.ts
)会引发以下lint错误:“module不是一个模块。”
这是项目的tsconfig配置文件:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"sourceMap": true,
"noImplicitThis": true,
"baseUrl": ".",
"types": [
"webpack-env",
"jest"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
如果有人能提供一个有效的方法来保留module.exports或在typescript中声明模块以仅允许导入其单个属性,我将不胜感激 :)