javascript - 在 Typescript/Javascript 中使用别名导出元素
问题描述
我想使用以下语法重命名要导出的函数。
export const { selectIds, selectEntities, selectAll, selectTotal } = adapter.getSelectors(selectState);
这样我就可以导入selectAll
到selectAllThings
其他文件中。
Typescript / Javascript可以做到这一点吗?
解决方案
是的,您可以在导入阶段设置别名:
import { selectAll as selectAllThings } from 'path_to_file';
或者您可以在解构阶段设置别名:
export const { selectAll: selectAllThings } = adapter.getSelectors(selectState);