Typescript导出命名为模块的默认值

时间:2019-12-20 23:39:32

标签: javascript reactjs typescript

我刚刚将我的React项目从javascript转换为打字稿,并且在许多实例中,我将在目录中拥有一个索引文件,并从相应目录中导出所有功能/组件。例如,目录可能如下所示:

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,并且我正在将webpack与babel-loader一起使用来编译这些文件。一切都可以正常运行,但是我在编辑器中遇到错误,因为打字稿无法理解这些导出。这是我的 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 个答案:

答案 0 :(得分:0)

如评论中所述,这似乎仍是第1阶段的功能,尚未在Typescript中实现。

相关问题