How to type async function using typescript
The type of an async function's return value is Promise<X>, where X is the fulfillment value that will be provided. In your case, since your function doesn't have a return anywhere, it would be Promise<void>, since the promise created by your function will be fulfilled with nothing in particular. (At runtime the fulfillment value will be undefined, but for type purposes, it's modelled as Promise<void>.)
Recent versions of TypeScript will default that return type for you, which is why the error relates to manager...
But the argument manager says 'Parameter manager implicitly has an any type.
This is the real issue with that code: manager has no type. The point of TypeScript is to provide strong typing at compile-time. It can't do that for your trainnlp function if you don't tell it what type manager should be. You want to provide a type for manager:
// (Just an example type) interface Manager { addAnswer(a: string, b: string, c: string): Promise<void>; save(a: string, b: boolean): void; } async function trainnlp(manager: Manager) { // ----------------------------^^^^^^^^^ await manager.addAnswer('en', 'greetings.arrival', "I've missed you"); manager.save('./model.nlp', true); }
On the playground
That clears the problem the error is flagging up. TypeScript will then infer the return type of the function, since it sees that it's an async function but never uses return, so its type is unambiguously Promise<void>.