Skip to content

Commit cf1b4e6

Browse files
committed
fix(48759): throw an error on using import expression with type arguments
1 parent 6894f91 commit cf1b4e6

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

src/compiler/checker.ts

+3
Original file line numberDiff line numberDiff line change
@@ -43862,6 +43862,9 @@ namespace ts {
4386243862
}
4386343863

4386443864
function checkGrammarExpressionWithTypeArguments(node: ExpressionWithTypeArguments | TypeQueryNode) {
43865+
if (isExpressionWithTypeArguments(node) && isImportKeyword(node.expression) && node.typeArguments) {
43866+
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_have_type_arguments);
43867+
}
4386543868
return checkGrammarTypeArguments(node, node.typeArguments);
4386643869
}
4386743870

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tests/cases/conformance/types/import/importWithTypeArguments.ts(1,1): error TS1326: Dynamic import cannot have type arguments.
2+
tests/cases/conformance/types/import/importWithTypeArguments.ts(2,11): error TS1326: Dynamic import cannot have type arguments.
3+
4+
5+
==== tests/cases/conformance/types/import/importWithTypeArguments.ts (2 errors) ====
6+
import<T>
7+
~~~~~~~~~
8+
!!! error TS1326: Dynamic import cannot have type arguments.
9+
const a = import<string, number>
10+
~~~~~~~~~~~~~~~~~~~~~~
11+
!!! error TS1326: Dynamic import cannot have type arguments.
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [importWithTypeArguments.ts]
2+
import<T>
3+
const a = import<string, number>
4+
5+
6+
//// [importWithTypeArguments.js]
7+
import;
8+
var a = (import);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/types/import/importWithTypeArguments.ts ===
2+
import<T>
3+
>T : Symbol(T)
4+
5+
const a = import<string, number>
6+
>a : Symbol(a, Decl(importWithTypeArguments.ts, 1, 5))
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/conformance/types/import/importWithTypeArguments.ts ===
2+
import<T>
3+
const a = import<string, number>
4+
>a : any
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import<T>
2+
const a = import<string, number>

0 commit comments

Comments
 (0)