I ended up having a promise like this in my code. Is it ok if I resolve in some condition with value of token which is a string (resolve(token))
and in one other condition resolve with another promise of type Promise<string>
: resolve(resultPromise);
const finalPromise = new Promise<string>(resolve => {
resultPromise.then(token => {
if (Pending) {
resolve(token);
} else if (!this.tokenIsValid(token)) {
resultPromise = requestToken();
resolve(resultPromise);
} else {
resolve(token);
}
});
I also tried changing it like this and got this typescript error:
//throwing error error noUnnecessaryCallbackWrapper: No need to wrap 'resolve' in another function. Just use it directly.
#second verison
const finalPromise = new Promise<string>(resolve => {
resultPromise.then(token => {
if (Pending) {
resolve(token);
} else if (!this.tokenIsValid(token)) {
requestToken().then(token => resolve(token));
} else {
resolve(token);
}
});
What would be the type of finalPromise in case I am returning resolve(resultPromise)
? what I am concerned is there is another function which gets the finalPromise
and the type of the input is Promise<string>
and I am worried that I am messing up responses and I am not aware.
How should I rewrite this so that finalPromise returns Promise of type string?
Thanks a lot for your help