Is it possible to write this code without using export const, but rather export async function?
This is a sample of the code, heavily simplified:
interface Product {
id: string;
name: string;
}
type Listener<Subject, Payload extends object> = (event: {
subject: Subject;
payload?: Partial<Payload>;
}) => Promise<void>;
export const onEvent: Listener<Product, never> = async (event) => {
await new Promise(function (resolve) {
// a simplified example of using the parameters
console.log(event.subject.id, event.subject.name);
setTimeout(resolve, 1000);
});
};
I'm wondering if it's possible to write this in the form of
export async function onEvent ... {
Without breaking it down into, for example
export async function onEvent(event: { subject: Product; payload?: never }): Promise<void> {
It doesn't seem like it after reading the current Typescript docs.
Listenerpart of your codebase or is it imported from a library?