I have a function that i need to export under two different names without redeclaring it.
Right now i'm stuck at doing this:
function handle() {
console.log('handle');
}
export function post {
return handle();
}
export function get() {
return handle();
}
But it doesn't scale well and it's ugly, especially if i have parameters that i need to pass to handle
.
Ideally it would look something like this, but it's not valid syntax:
function handle() {
console.log('handle');
}
export {handle} as get;
export {handle} as post;
Is there a way to do this?
I think that you need to change your TypeScript code. You will find more info at the official documentation.
function handle() {
console.log('handle');
}
export { handle as get };
export { handle as post };
And then you can import it as you want
import { get } from './your-file-path';
Found a solution:
function handle() {
console.log('handle');
}
export let get = handle;
export let post = handle;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With