我有一个函数,需要以两个不同的名称导出而无需重新声明。
现在,我坚持这样做:
function handle() {
console.log('handle');
}
export function post {
return handle();
}
export function get() {
return handle();
}
Run Code Online (Sandbox Code Playgroud)
但这伸缩性不好,而且很难看,尤其是当我有需要传递给的参数时handle。
理想情况下,它看起来像这样,但是它是无效的语法:
function handle() {
console.log('handle');
}
export {handle} as get;
export {handle} as post;
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我认为您需要更改TypeScript代码。您可以在官方文档中找到更多信息。
function handle() {
console.log('handle');
}
export { handle as get };
export { handle as post };
Run Code Online (Sandbox Code Playgroud)
然后您可以根据需要导入它
import { get } from './your-file-path';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
854 次 |
| 最近记录: |