I want to use a strict return type statement in Typescript.
When I write a function with a single if-then-else statement, the TS Linter of vscode is smart enough to see accept my return value:
If I try to do the same if a single .then().catch() block, in which there aren't any other possibilites for the function to go, my linter won't accept the return type.
Returning the promise won't work aswell (as intended)
I also checked with a .finally() statement, which doesn't work aswell and isn't intended to be used in my situation.
Source:
var myPromise = new Promise(function (resolve, reject) {
if (Math.round(Math.random()) == 1) {
resolve("yay")
} else {
reject("nay")
}
});
function returnYayOrNay(): string {
myPromise
.then((result) => {
return result
})
.catch((result) => {
return result
})
}
Edit 1: I want to return a string as in Picture2