mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 10:46:28 -05:00
Report an error if dynamic import specifier is not assigable to type string
This commit is contained in:
@@ -14873,6 +14873,10 @@ namespace ts {
|
||||
grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules);
|
||||
}
|
||||
|
||||
const specifierType = checkExpression(node.specifier);
|
||||
if (!isTypeAssignableTo(specifierType, stringType)) {
|
||||
error(node.specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType));
|
||||
}
|
||||
// resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal
|
||||
const moduleSymbol = resolveExternalModuleName(node, node.specifier);
|
||||
if (moduleSymbol) {
|
||||
|
||||
@@ -3165,6 +3165,10 @@
|
||||
"category": "Error",
|
||||
"code": 7035
|
||||
},
|
||||
"Dynamic import's specifier must be of type 'string', but here has type '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 7036
|
||||
},
|
||||
"You cannot rename this element.": {
|
||||
"category": "Error",
|
||||
"code": 8000
|
||||
|
||||
Reference in New Issue
Block a user