I'm dealing with a code that makes calls to an async function. In this case, the run
method performs an await
call to a method that returns a string. How can I transform the run
method to return, again, a promise?
I searched the Internet, but I cannot find a solution. I'm new to Typescript and asynchronous programming.
I'd also like to ask: Does the await
keyword "transform" a returned promise in a string? The result is a string, but why do I not have to unwrap it with .then()
to obtain the string? If the result was a promise, I could return it in the run
method, but run
must return a promise.
public async run(): Promise<IMyType> {
log.info("Running item1 ...");
let result: IMyType = {
name: "name1",
outcome: undefined,
message: "",
various: {}
};
result = await this.runCheck(result);
if (result.outcome) {
result.message = this.successMessage;
} else {
result.message = this.failMessage;
}
return result;
}
private async runCheck(
result: IMyType
): Promise<IMyTypet>