【问题标题】:Is it possible to import similarly named exports from multiple modules是否可以从多个模块导入类似命名的导出
【发布时间】:2021-10-08 12:37:30
【问题描述】:

假设我有一个模块 AB 都导出:

export const Name = 'Something'

目前唯一可行的解​​决方案是从每个模块手动导入Name

import { Name } from 'A'
// or
import { Name } from 'B'

但是是否可以将所有导出的Name 导入到某种列表中?例如:

const Names = import 'all Name from all modules'

【问题讨论】:

    标签: node.js typescript node-modules create-react-app


    【解决方案1】:

    如果您需要在同一个文件中进行两个导出,您可以使用as 为它们分配别名。示例:

    import { Name as AName } from 'A'
    import { Name as BName } from 'B'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      • 1970-01-01
      • 2019-09-24
      • 1970-01-01
      • 2022-07-10
      相关资源
      最近更新 更多