【发布时间】:2020-01-22 21:29:41
【问题描述】:
在JS文件中编写的以下模块:
module.exports = {
propA: 1,
propB: 2
}
允许稍后从模块中导入属性,例如:
import { propA } from 'path/to/module'
但是,将文件格式更改为 typescript(如 module.ts)会导致以下问题 linter issue 'module is not a 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 ,我将不胜感激:)
...或者至少可以声明导出对象的模块,以后只允许导入它的单个属性
【问题讨论】:
-
这可能会有所帮助:stackoverflow.com/a/35401923/5271656
标签: typescript