Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eb03ae8

Browse filesBrowse files
committed
Added shortcut in checkAwaitedType for isolatedModules
1 parent 379d74a commit eb03ae8
Copy full SHA for eb03ae8

4 files changed

+211Lines changed: 211 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9687,6 +9687,12 @@ namespace ts {
96879687
// side of the `Promise` class, which would be `{ new <T>(...): Promise<T> }`.
96889688

96899689
let promiseType = getTypeFromTypeNode(node.type);
9690+
if (promiseType === unknownType && compilerOptions.isolatedModules) {
9691+
// If we are compiling with isolatedModules, we may not be able to resolve the
9692+
// type as a value. As such, we will just return unknownType;
9693+
return unknownType;
9694+
}
9695+
96909696
let promiseConstructor = getMergedSymbol(promiseType.symbol);
96919697
if (!promiseConstructor || !symbolIsValue(promiseConstructor)) {
96929698
error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeToString(promiseType));
Collapse file
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts(1,27): error TS2307: Cannot find module 'missing'.
2+
3+
4+
==== tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts (1 errors) ====
5+
import { MyPromise } from "missing";
6+
~~~~~~~~~
7+
!!! error TS2307: Cannot find module 'missing'.
8+
9+
declare var p: Promise<number>;
10+
declare var mp: MyPromise<number>;
11+
12+
async function f0() { }
13+
async function f1(): Promise<void> { }
14+
async function f3(): MyPromise<void> { }
15+
16+
let f4 = async function() { }
17+
let f5 = async function(): Promise<void> { }
18+
let f6 = async function(): MyPromise<void> { }
19+
20+
let f7 = async () => { };
21+
let f8 = async (): Promise<void> => { };
22+
let f9 = async (): MyPromise<void> => { };
23+
let f10 = async () => p;
24+
let f11 = async () => mp;
25+
let f12 = async (): Promise<number> => mp;
26+
let f13 = async (): MyPromise<number> => p;
27+
28+
let o = {
29+
async m1() { },
30+
async m2(): Promise<void> { },
31+
async m3(): MyPromise<void> { }
32+
};
33+
34+
class C {
35+
async m1() { }
36+
async m2(): Promise<void> { }
37+
async m3(): MyPromise<void> { }
38+
static async m4() { }
39+
static async m5(): Promise<void> { }
40+
static async m6(): MyPromise<void> { }
41+
}
42+
43+
module M {
44+
export async function f1() { }
45+
}
Collapse file
+119Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//// [asyncAwaitIsolatedModules_es6.ts]
2+
import { MyPromise } from "missing";
3+
4+
declare var p: Promise<number>;
5+
declare var mp: MyPromise<number>;
6+
7+
async function f0() { }
8+
async function f1(): Promise<void> { }
9+
async function f3(): MyPromise<void> { }
10+
11+
let f4 = async function() { }
12+
let f5 = async function(): Promise<void> { }
13+
let f6 = async function(): MyPromise<void> { }
14+
15+
let f7 = async () => { };
16+
let f8 = async (): Promise<void> => { };
17+
let f9 = async (): MyPromise<void> => { };
18+
let f10 = async () => p;
19+
let f11 = async () => mp;
20+
let f12 = async (): Promise<number> => mp;
21+
let f13 = async (): MyPromise<number> => p;
22+
23+
let o = {
24+
async m1() { },
25+
async m2(): Promise<void> { },
26+
async m3(): MyPromise<void> { }
27+
};
28+
29+
class C {
30+
async m1() { }
31+
async m2(): Promise<void> { }
32+
async m3(): MyPromise<void> { }
33+
static async m4() { }
34+
static async m5(): Promise<void> { }
35+
static async m6(): MyPromise<void> { }
36+
}
37+
38+
module M {
39+
export async function f1() { }
40+
}
41+
42+
//// [asyncAwaitIsolatedModules_es6.js]
43+
var __awaiter = (this && this.__awaiter) || function (args, generator) {
44+
var PromiseConstructor = args[1] || Promise;
45+
return new PromiseConstructor(function (resolve, reject) {
46+
generator = generator.call(args[0], args[2]);
47+
function cast(value) { return value instanceof PromiseConstructor ? value : new PromiseConstructor(function (resolve) { resolve(value); }); }
48+
function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
49+
function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }
50+
function step(verb, value) {
51+
var result = generator[verb](value);
52+
result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);
53+
}
54+
step("next", void 0);
55+
});
56+
};
57+
function f0() {
58+
return __awaiter([this], function* () { });
59+
}
60+
function f1() {
61+
return __awaiter([this, Promise], function* () { });
62+
}
63+
function f3() {
64+
return __awaiter([this, MyPromise], function* () { });
65+
}
66+
let f4 = function () {
67+
return __awaiter([this], function* () { });
68+
};
69+
let f5 = function () {
70+
return __awaiter([this, Promise], function* () { });
71+
};
72+
let f6 = function () {
73+
return __awaiter([this, MyPromise], function* () { });
74+
};
75+
let f7 = () => __awaiter([this], function* () { });
76+
let f8 = () => __awaiter([this, Promise], function* () { });
77+
let f9 = () => __awaiter([this, MyPromise], function* () { });
78+
let f10 = () => __awaiter([this], function* () { return p; });
79+
let f11 = () => __awaiter([this], function* () { return mp; });
80+
let f12 = () => __awaiter([this, Promise], function* () { return mp; });
81+
let f13 = () => __awaiter([this, MyPromise], function* () { return p; });
82+
let o = {
83+
m1() {
84+
return __awaiter([this], function* () { });
85+
},
86+
m2() {
87+
return __awaiter([this, Promise], function* () { });
88+
},
89+
m3() {
90+
return __awaiter([this, MyPromise], function* () { });
91+
}
92+
};
93+
class C {
94+
m1() {
95+
return __awaiter([this], function* () { });
96+
}
97+
m2() {
98+
return __awaiter([this, Promise], function* () { });
99+
}
100+
m3() {
101+
return __awaiter([this, MyPromise], function* () { });
102+
}
103+
static m4() {
104+
return __awaiter([this], function* () { });
105+
}
106+
static m5() {
107+
return __awaiter([this, Promise], function* () { });
108+
}
109+
static m6() {
110+
return __awaiter([this, MyPromise], function* () { });
111+
}
112+
}
113+
var M;
114+
(function (M) {
115+
function f1() {
116+
return __awaiter([this], function* () { });
117+
}
118+
M.f1 = f1;
119+
})(M || (M = {}));
Collapse file
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// @target: ES6
2+
// @isolatedModules: true
3+
import { MyPromise } from "missing";
4+
5+
declare var p: Promise<number>;
6+
declare var mp: MyPromise<number>;
7+
8+
async function f0() { }
9+
async function f1(): Promise<void> { }
10+
async function f3(): MyPromise<void> { }
11+
12+
let f4 = async function() { }
13+
let f5 = async function(): Promise<void> { }
14+
let f6 = async function(): MyPromise<void> { }
15+
16+
let f7 = async () => { };
17+
let f8 = async (): Promise<void> => { };
18+
let f9 = async (): MyPromise<void> => { };
19+
let f10 = async () => p;
20+
let f11 = async () => mp;
21+
let f12 = async (): Promise<number> => mp;
22+
let f13 = async (): MyPromise<number> => p;
23+
24+
let o = {
25+
async m1() { },
26+
async m2(): Promise<void> { },
27+
async m3(): MyPromise<void> { }
28+
};
29+
30+
class C {
31+
async m1() { }
32+
async m2(): Promise<void> { }
33+
async m3(): MyPromise<void> { }
34+
static async m4() { }
35+
static async m5(): Promise<void> { }
36+
static async m6(): MyPromise<void> { }
37+
}
38+
39+
module M {
40+
export async function f1() { }
41+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.