I've a sample Promise function like below. On success I return a number
and on false I return string
. The compiler is complaining to specify some kind of generic type to the promise. In this case what type I've to specify? Do I've to specify like Promise<number>
or Promise<number | string>
?
function test(arg: string): Promise {
return new Promise((resolve, reject) => {
if (arg === "a") {
resolve(1);
} else {
reject("1");
}
});
}