I have a sample Promise function that is shown below. When successful, it returns a number
, and when unsuccessful, it returns a string
. The compiler is asking me to specify some kind of generic type for the promise. In this scenario, what type should I specify? Should I use Promise<number>
or Promise<number | string>
?
function test(arg: string): Promise {
return new Promise((resolve, reject) => {
if (arg === "a") {
resolve(1);
} else {
reject("1");
}
});
}