Added shortcut in checkAwaitedType for isolatedModules

This commit is contained in:
Ron Buckton 2015-06-18 15:41:19 -07:00
parent 379d74a1bf
commit eb03ae8e7c
4 changed files with 211 additions and 0 deletions

View File

@ -9687,6 +9687,12 @@ namespace ts {
// side of the `Promise` class, which would be `{ new <T>(...): Promise<T> }`.
let promiseType = getTypeFromTypeNode(node.type);
if (promiseType === unknownType && compilerOptions.isolatedModules) {
// If we are compiling with isolatedModules, we may not be able to resolve the
// type as a value. As such, we will just return unknownType;
return unknownType;
}
let promiseConstructor = getMergedSymbol(promiseType.symbol);
if (!promiseConstructor || !symbolIsValue(promiseConstructor)) {
error(node, Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeToString(promiseType));

View File

@ -0,0 +1,45 @@
tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts(1,27): error TS2307: Cannot find module 'missing'.
==== tests/cases/conformance/async/es6/asyncAwaitIsolatedModules_es6.ts (1 errors) ====
import { MyPromise } from "missing";
~~~~~~~~~
!!! error TS2307: Cannot find module 'missing'.
declare var p: Promise<number>;
declare var mp: MyPromise<number>;
async function f0() { }
async function f1(): Promise<void> { }
async function f3(): MyPromise<void> { }
let f4 = async function() { }
let f5 = async function(): Promise<void> { }
let f6 = async function(): MyPromise<void> { }
let f7 = async () => { };
let f8 = async (): Promise<void> => { };
let f9 = async (): MyPromise<void> => { };
let f10 = async () => p;
let f11 = async () => mp;
let f12 = async (): Promise<number> => mp;
let f13 = async (): MyPromise<number> => p;
let o = {
async m1() { },
async m2(): Promise<void> { },
async m3(): MyPromise<void> { }
};
class C {
async m1() { }
async m2(): Promise<void> { }
async m3(): MyPromise<void> { }
static async m4() { }
static async m5(): Promise<void> { }
static async m6(): MyPromise<void> { }
}
module M {
export async function f1() { }
}

View File

@ -0,0 +1,119 @@
//// [asyncAwaitIsolatedModules_es6.ts]
import { MyPromise } from "missing";
declare var p: Promise<number>;
declare var mp: MyPromise<number>;
async function f0() { }
async function f1(): Promise<void> { }
async function f3(): MyPromise<void> { }
let f4 = async function() { }
let f5 = async function(): Promise<void> { }
let f6 = async function(): MyPromise<void> { }
let f7 = async () => { };
let f8 = async (): Promise<void> => { };
let f9 = async (): MyPromise<void> => { };
let f10 = async () => p;
let f11 = async () => mp;
let f12 = async (): Promise<number> => mp;
let f13 = async (): MyPromise<number> => p;
let o = {
async m1() { },
async m2(): Promise<void> { },
async m3(): MyPromise<void> { }
};
class C {
async m1() { }
async m2(): Promise<void> { }
async m3(): MyPromise<void> { }
static async m4() { }
static async m5(): Promise<void> { }
static async m6(): MyPromise<void> { }
}
module M {
export async function f1() { }
}
//// [asyncAwaitIsolatedModules_es6.js]
var __awaiter = (this && this.__awaiter) || function (args, generator) {
var PromiseConstructor = args[1] || Promise;
return new PromiseConstructor(function (resolve, reject) {
generator = generator.call(args[0], args[2]);
function cast(value) { return value instanceof PromiseConstructor ? value : new PromiseConstructor(function (resolve) { resolve(value); }); }
function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }
function step(verb, value) {
var result = generator[verb](value);
result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);
}
step("next", void 0);
});
};
function f0() {
return __awaiter([this], function* () { });
}
function f1() {
return __awaiter([this, Promise], function* () { });
}
function f3() {
return __awaiter([this, MyPromise], function* () { });
}
let f4 = function () {
return __awaiter([this], function* () { });
};
let f5 = function () {
return __awaiter([this, Promise], function* () { });
};
let f6 = function () {
return __awaiter([this, MyPromise], function* () { });
};
let f7 = () => __awaiter([this], function* () { });
let f8 = () => __awaiter([this, Promise], function* () { });
let f9 = () => __awaiter([this, MyPromise], function* () { });
let f10 = () => __awaiter([this], function* () { return p; });
let f11 = () => __awaiter([this], function* () { return mp; });
let f12 = () => __awaiter([this, Promise], function* () { return mp; });
let f13 = () => __awaiter([this, MyPromise], function* () { return p; });
let o = {
m1() {
return __awaiter([this], function* () { });
},
m2() {
return __awaiter([this, Promise], function* () { });
},
m3() {
return __awaiter([this, MyPromise], function* () { });
}
};
class C {
m1() {
return __awaiter([this], function* () { });
}
m2() {
return __awaiter([this, Promise], function* () { });
}
m3() {
return __awaiter([this, MyPromise], function* () { });
}
static m4() {
return __awaiter([this], function* () { });
}
static m5() {
return __awaiter([this, Promise], function* () { });
}
static m6() {
return __awaiter([this, MyPromise], function* () { });
}
}
var M;
(function (M) {
function f1() {
return __awaiter([this], function* () { });
}
M.f1 = f1;
})(M || (M = {}));

View File

@ -0,0 +1,41 @@
// @target: ES6
// @isolatedModules: true
import { MyPromise } from "missing";
declare var p: Promise<number>;
declare var mp: MyPromise<number>;
async function f0() { }
async function f1(): Promise<void> { }
async function f3(): MyPromise<void> { }
let f4 = async function() { }
let f5 = async function(): Promise<void> { }
let f6 = async function(): MyPromise<void> { }
let f7 = async () => { };
let f8 = async (): Promise<void> => { };
let f9 = async (): MyPromise<void> => { };
let f10 = async () => p;
let f11 = async () => mp;
let f12 = async (): Promise<number> => mp;
let f13 = async (): MyPromise<number> => p;
let o = {
async m1() { },
async m2(): Promise<void> { },
async m3(): MyPromise<void> { }
};
class C {
async m1() { }
async m2(): Promise<void> { }
async m3(): MyPromise<void> { }
static async m4() { }
static async m5(): Promise<void> { }
static async m6(): MyPromise<void> { }
}
module M {
export async function f1() { }
}