1function delay(milliseconds: number, count: number): Promise<number> {
2 return new Promise<number>(resolve => {
3 setTimeout(() => {
4 resolve(count);
5 }, milliseconds);
6 });
7}
8
9// async function always returns a Promise
10async function dramaticWelcome(): Promise<void> {
11 console.log("Hello");
12
13 for (let i = 0; i < 5; i++) {
14 // await is converting Promise<number> into number
15 const count: number = await delay(500, i);
16 console.log(count);
17 }
18
19 console.log("World!");
20}
21
22dramaticWelcome();
1// async anonymous function always returns a Promise
2const dramaticWelcome: Promise<void> = async () => {
3 console.log("Hello");
4
5 for (let i = 0; i < 5; i++) {
6 // await is converting Promise<number> into number
7 const count: number = await delay(500, i);
8 console.log(count);
9 }
10
11 console.log("World!");
12}
13