简体   繁体   English

打字稿导出命名为模块的默认值

[英]Typescript export named default of module

I have just converted my React project from javascript to typescript, and I have many instances where I'll have an index file in a directory and export all the functions/components from the respective directory.我刚刚将我的 React 项目从 javascript 转换为 typescript,并且我有很多实例,我将在一个目录中有一个索引文件并从相应的目录中导出所有函数/组件。 For example, the directory might look like this:例如,目录可能如下所示:

components
|--index.js
|--ComponentA
|--ComponentB
|--ComponentC
|...

And index.js would contain: index.js 将包含:

export ComponentA from './ComponentA'
export ComponentB from './ComponentB'
export ComponentC from './ComponentC'
...

Which I believe babel converts to:我相信 babel 会转换为:

export { default as ComponentA } from './ComponentA'
...

I've converted all .js/.jsx files to .ts/.tsx and I'm using webpack with babel-loader to compile these files.我已经将所有 .js/.jsx 文件转换为 .ts/.tsx 并且我使用 webpack 和 babel-loader 来编译这些文件。 Everyting runs just fine, but I get eslint errors in my editor because typescript doesn't understand these exports. Everyting 运行得很好,但我的编辑器中出现 eslint 错误,因为打字稿不理解这些导出。 Here's my tsconfig.json file:这是我的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/**/*"
        ]
    }
}

And .eslintrc.json:.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"
  ]
}

How can I get typescript to understand export Component from './Component ?如何让打字稿理解export Component from './Component

正如评论中提到的,看起来这仍然是第 1 阶段的功能,尚未在 Typescript 中实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 转换为Typescript后,模块没有默认导出 - Module has not default export after converting to Typescript 如何在TypeScript中使用对象作为默认导出声明模块 - How to declare a module in TypeScript with an object as default export 导入默认导出和命名导出是否会将模块加载两次? - Does importing the default export along with a named export load the module twice? Jest:模拟ES6模块,默认和命名导出 - Jest: Mock ES6 Module with both default and named export 请求的模块“./react.js”不提供名为“默认”的导出 - The requested module './react.js' does not provide an export named 'default' SyntaxError:请求的模块“sqlite”不提供名为“default”的导出 - SyntaxError: The requested module 'sqlite' does not provide an export named 'default' 请求的模块不通过快速路由提供名为 default 的导出 - The requested module does not provide an export named default via express routing 将“导出默认值”更改为命名导出 - Change 'export default' to named export jspm / jQuery / TypeScript - 模块“jquery”没有默认导出 - jspm / jQuery / TypeScript - module “jquery” has no default export 默认导出为全局变量Typescript 1.8 --module UMD - Default export as global variable Typescript 1.8 --module UMD
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM