我正在寻找一种优雅的方法来导入所有命名导出,而不必导入默认导出。
在一个文件中,我导出许多命名常量以及默认值:
// myModule.js
const myDefault = 'my default'
export const named1 = 'named1'
export const named2 = 'named2'
// many more named exports - otherwise this would not be an issue...
export default myDefault
在另一个文件中,我希望有一种优雅的方式来导入所有命名导出only,无需导入默认值:
// anotherFile.js
// this is what I would like to do, but syntax is not supported, right?
import { * as namedOnly } from './myModule'
I do not想要:
// anotherFile.js
import myDefault, * as namedOnly from './myModule'
因为我不需要默认的anotherFile.js
我的 linting 工具让我烦恼
已定义但未使用myDefault
。我也不想:
// anotherFile.js
import {
named1,
named2,
... // many more
} from './myModule'
因为打字太多了。我也做not想要object.omit
默认值:
// anotherFile.js
import omit from 'object.omit'
import * as all from './myModule'
const namedOnly = omit(all, 'default')
谢谢你的帮助!