I'm having trouble with the syntax for an async (arrow) function as a type/interface attribute. I've already done a bit of research but didn't found much except this https://github.com/Microsoft/TypeScript/issues/22035 It's not 100% accurate to my case but better than nothing. And still doesn't work for me...
Here is about the code I have in the declaration (simplified) :
export type MyType = {
att1: string;
funct: async (param1: string, param2: string) => Promise<string[]>;
};
And where I use it (example, not my actual code) :
import { MyType } from "./MyType";
const myObject: MyType = {
att1: "First attribute";
funct: async (param1: string, param2: string): Promise<string[]> => {
// Code below is an example, in my case it's a database querying
// But anyway, it's something async
return new Promise((resolve, reject): void => {
setTimeout((): void => {
resolve(["string1", "string2"]);
}, 5000);
});
};
};
The TypeScript transpiler says it cannot find the name "async". How do I tell the function "funct" in MyType is async? I need to use await in it...