Currently, I am learning Promise with TypeScript and I am facing an issue where the promises in my code are not executing sequentially as expected. Despite researching online for 2 days, I have been unable to find a solution. If anyone could provide some insight or suggestions, I would greatly appreciate it. Thank you.
step1()
.then(() => {
return step2();
})
.then(() => {
return step3();
});
function step1() : Promise<void>{
return new Promise<void>(() => {
setTimeout(() => {console.log("1");}, 1000);
});
}
function step2() : Promise<void>{
return new Promise<void>(() => {
setTimeout(() => {console.log("2");}, 1000);
});
}
function step3() : Promise<void>{
return new Promise<void>(() => {
setTimeout(() => {console.log("3");}, 1000);
});
}
The execution seems to be stuck at step 1 without proceeding to the next steps. No other functions are being called after step 1.