mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix where we report noImplicitAny error in dynamic import
This commit is contained in:
+11
-4
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user