javascript - 打字稿导出命名为模块的默认值
问题描述
我刚刚将我的 React 项目从 javascript 转换为 typescript,并且我有很多实例,其中我将在目录中有一个索引文件并从相应目录导出所有函数/组件。例如,目录可能如下所示:
components
|--index.js
|--ComponentA
|--ComponentB
|--ComponentC
|...
index.js 将包含:
export ComponentA from './ComponentA'
export ComponentB from './ComponentB'
export ComponentC from './ComponentC'
...
我相信 babel 转换为:
export { default as ComponentA } from './ComponentA'
...
我已经将所有 .js/.jsx 文件转换为 .ts/.tsx 并且我正在使用带有 babel-loader 的 webpack 来编译这些文件。Everyting 运行得很好,但我在编辑器中遇到 eslint 错误,因为 typescript 不理解这些导出。这是我的tsconfig.json文件:
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": false,
"module": "es6",
"target": "es6",
"jsx": "preserve",
"lib": ["es5", "es6", "dom"],
"esModuleInterop": true,
"allowJs": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
},
"include": [
"./src/**/*"
],
"types": [
"@reachify/graphql-schema"
],
"awesomeTypescriptLoaderOptions": {
"reportFiles": [
"./src/**/*"
]
}
}
和.eslintrc.json:
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"env": {
"browser": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint/eslint-plugin"
]
}
我怎样才能让打字稿理解export Component from './Component
?
解决方案
正如评论中提到的,看起来这仍然是第 1 阶段的功能,尚未在 Typescript 中实现。
推荐阅读
- r - list[1:3] 和 list[1,2,3] 之间的区别?为什么索引列表 [1:3] 在描述中给出的列表中引发错误
- numpy - 如何将 csv 文件从 S3 存储桶下载到 numpy 数组中
- android - 升级到 0.60.4 后 React-native 版本不匹配
- python-3.x - 为包含编码字节字符串的文件生成 sphinx autodoc
- css - 为什么 box-sizing 在这里不适用?
- r - 使用带有重置的 dplyr 的 R 累积和
- python - Pygame中的换行符与输入框中的Unicode
- google-bigquery - 是否可以禁用在 BigQuery 中保存结果和/或导出查询结果的功能?
- java - Elasticsearch 7.2 java 客户端 SSL 配置失败:bad_certificate
- json - 我如何从我的 json 中的另一个 CRUD 中获取价值