导出和导出默认一个变量
Export and export default a variable
做这样的事情的正确方法是什么?我的目标是让我的出口清单不必重复。现在我必须制作两个导出列表,一个用于导出,一个用于默认导出。
const exports = {
Something,
SomethingElse
}
export exports
export default exports
我的目标是能够像这样导入:
import everything from 'my_module'
或
import {Something} from 'my_module'
export exports
不是有效语法,它看起来类似于 something that TypeScript did support 但不推荐使用现代语法。不要使用它。
export default exports;
和 import everything from 'my_module';
可以一起工作,但是 因为它不适用于命名导入。
改为使用命名导出:
export {
Something,
SomethingElse
}
(或者把export
放在Something
和SomethingElse
的声明右边),然后你可以选择
import {Something} from 'my_module';
或
import * as everything from 'my_module';
做这样的事情的正确方法是什么?我的目标是让我的出口清单不必重复。现在我必须制作两个导出列表,一个用于导出,一个用于默认导出。
const exports = {
Something,
SomethingElse
}
export exports
export default exports
我的目标是能够像这样导入:
import everything from 'my_module'
或
import {Something} from 'my_module'
export exports
不是有效语法,它看起来类似于 something that TypeScript did support 但不推荐使用现代语法。不要使用它。
export default exports;
和 import everything from 'my_module';
可以一起工作,但是
改为使用命名导出:
export {
Something,
SomethingElse
}
(或者把export
放在Something
和SomethingElse
的声明右边),然后你可以选择
import {Something} from 'my_module';
或
import * as everything from 'my_module';