Fix where we report noImplicitAny error in dynamic import

This commit is contained in:
Kanchalai Tanglertsampan
2017-03-24 13:24:50 -07:00
parent e1ba8553b6
commit 265d0c020b
+11 -4
View File
@@ -1,4 +1,4 @@
/// <reference path="moduleNameResolver.ts"/>
/// <reference path="moduleNameResolver.ts"/>
/// <reference path="binder.ts"/>
/* @internal */
@@ -284,6 +284,7 @@ namespace ts {
let deferredGlobalAsyncIterableIteratorType: GenericType;
let deferredGlobalTemplateStringsArrayType: ObjectType;
let deferredJsxElementClassType: Type;
let deferredGlobalPromiseAnyType: Type;
let deferredNodes: Node[];
let deferredUnusedIdentifierNodes: Node[];
@@ -3455,6 +3456,11 @@ namespace ts {
// Use the type of the initializer expression if one is present
if (declaration.initializer) {
const type = checkDeclarationInitializer(declaration);
if (isImportCall(declaration.initializer)) {
if (noImplicitAny && type === getGlobalPromiseAnyType()) {
error(declaration, Diagnostics.Cannot_resolve_dynamic_import_implicitly_has_a_Promise_any_type); }
}
return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality);
}
@@ -6083,6 +6089,10 @@ namespace ts {
return deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise", /*arity*/ 1, reportErrors)) || emptyGenericType;
}
function getGlobalPromiseAnyType() {
return deferredGlobalPromiseAnyType || (deferredGlobalPromiseAnyType = createPromiseType(anyType));
}
function getGlobalPromiseConstructorSymbol(reportErrors: boolean): Symbol | undefined {
return deferredGlobalPromiseConstructorSymbol || (deferredGlobalPromiseConstructorSymbol = getGlobalValueSymbol("Promise", reportErrors));
}
@@ -14897,9 +14907,6 @@ namespace ts {
return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol));
}
}
if (noImplicitAny) {
error(node, Diagnostics.Cannot_resolve_dynamic_import_implicitly_has_a_Promise_any_type);
}
return createPromiseReturnType(node, anyType);
}