• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) Microsoft Corporation. All rights reserved.
3* Copyright (c) 2023 Huawei Device Co., Ltd.
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8*     http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*
16* This file has been modified by Huawei to verify type inference by adding verification statements.
17*/
18
19// === tests/cases/compiler/es2017basicAsync.ts ===
20declare function AssertType(value:any, type:string):void;
21async (): Promise<void> => {
22AssertType(async (): Promise<void> => {    await 0;}, "() => Promise<void>");
23
24    await 0;
25AssertType(await 0, "int");
26AssertType(0, "int");
27}
28
29async function asyncFunc() {
30    await 0;
31AssertType(await 0, "int");
32AssertType(0, "int");
33}
34
35const asyncArrowFunc = async (): Promise<void> => {
36AssertType(asyncArrowFunc, "() => Promise<void>");
37AssertType(async (): Promise<void> => {    await 0;}, "() => Promise<void>");
38
39    await 0;
40AssertType(await 0, "int");
41AssertType(0, "int");
42}
43
44async function asyncIIFE() {
45    await 0;
46AssertType(await 0, "int");
47AssertType(0, "int");
48
49    await (async function(): Promise<void> {
50AssertType(await (async function(): Promise<void> {        await 1;    })(), "void");
51AssertType((async function(): Promise<void> {        await 1;    })(), "Promise<void>");
52AssertType((async function(): Promise<void> {        await 1;    }), "() => Promise<void>");
53AssertType(async function(): Promise<void> {        await 1;    }, "() => Promise<void>");
54
55        await 1;
56AssertType(await 1, "int");
57AssertType(1, "int");
58
59    })();
60
61    await (async function asyncNamedFunc(): Promise<void> {
62AssertType(await (async function asyncNamedFunc(): Promise<void> {        await 1;    })(), "void");
63AssertType((async function asyncNamedFunc(): Promise<void> {        await 1;    })(), "Promise<void>");
64AssertType((async function asyncNamedFunc(): Promise<void> {        await 1;    }), "() => Promise<void>");
65AssertType(async function asyncNamedFunc(): Promise<void> {        await 1;    }, "() => Promise<void>");
66AssertType(asyncNamedFunc, "() => Promise<void>");
67
68        await 1;
69AssertType(await 1, "int");
70AssertType(1, "int");
71
72    })();
73
74    await (async (): Promise<void> => {
75AssertType(await (async (): Promise<void> => {        await 1;    })(), "void");
76AssertType((async (): Promise<void> => {        await 1;    })(), "Promise<void>");
77AssertType((async (): Promise<void> => {        await 1;    }), "() => Promise<void>");
78AssertType(async (): Promise<void> => {        await 1;    }, "() => Promise<void>");
79
80        await 1;
81AssertType(await 1, "int");
82AssertType(1, "int");
83
84    })();
85}
86
87class AsyncClass {
88    asyncPropFunc = async function(): Promise<void> {
89        await 2;
90AssertType(await 2, "int");
91AssertType(2, "int");
92    }
93
94    asyncPropNamedFunc = async function namedFunc(): Promise<void> {
95        await 2;
96AssertType(await 2, "int");
97AssertType(2, "int");
98    }
99
100    asyncPropArrowFunc = async (): Promise<void> => {
101        await 2;
102AssertType(await 2, "int");
103AssertType(2, "int");
104    }
105
106    async asyncMethod(): Promise<void> {
107        await 2;
108AssertType(await 2, "int");
109AssertType(2, "int");
110    }
111}
112
113
114