Skip to content

Commit 792ffcc

Browse files
authored
fix: disallow NoSubstitutionTemplate in module import attribute types (#64243)
1 parent 619d485 commit 792ffcc

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎tsc/internal/checker/grammarchecks.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,7 @@ func (c *Checker) checkGrammarImportAttributesType(attributes *ast.TypeLiteralNo
22292229
}
22302230

22312231
typeNode := propertySignature.Type
2232-
if !ast.IsStringLiteralLikeType(typeNode) {
2232+
if !ast.IsLiteralTypeNode(typeNode) || !ast.IsStringLiteral(typeNode.AsLiteralTypeNode().Literal) {
22332233
return c.grammarErrorOnNode(typeNode, diagnostics.An_import_attributes_property_must_have_a_string_literal_type_annotation)
22342234
}
22352235
}

‎tsc/testdata/baselines/reference/compiler/importAttributeType1.errors.txt‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
Property 'type' is incompatible with index signature.
88
Type '{ name: string; }' is not assignable to type 'string'.
99
/checkErrors.d.ts(2,45): error TS1555: An import attributes property must have a string literal type annotation.
10-
/checkErrors.d.ts(3,33): error TS1555: An import attributes property must have a string literal type annotation.
10+
/checkErrors.d.ts(3,37): error TS1555: An import attributes property must have a string literal type annotation.
11+
/checkErrors.d.ts(4,37): error TS1555: An import attributes property must have a string literal type annotation.
12+
/checkErrors.d.ts(5,33): error TS1555: An import attributes property must have a string literal type annotation.
1113
/valid.d.ts(11,38): error TS1555: An import attributes property must have a string literal type annotation.
1214

1315

@@ -41,7 +43,7 @@
4143
text.toUpperCase();
4244
data.version.toFixed();
4345

44-
==== /checkErrors.d.ts (5 errors) ====
46+
==== /checkErrors.d.ts (7 errors) ====
4547
declare module "*.numberValue" with { type: number } {}
4648
~~~~~~~~~~~~~~~~
4749
!!! error TS2322: Type '{ type: number; }' is not assignable to type 'ImportAttributes'.
@@ -55,6 +57,12 @@
5557
!!! error TS2322: Property 'type' is incompatible with index signature.
5658
!!! error TS2322: Type '{ name: string; }' is not assignable to type 'string'.
5759
~~~~~~~~~~~~~~~~
60+
!!! error TS1555: An import attributes property must have a string literal type annotation.
61+
declare module "*.css" with { type: `css` } {}
62+
~~~~~
63+
!!! error TS1555: An import attributes property must have a string literal type annotation.
64+
declare module "*.css" with { type: `css${''}` } {}
65+
~~~~~~~~~~
5866
!!! error TS1555: An import attributes property must have a string literal type annotation.
5967
declare module "*" with { type: "md" | "markdown" } {}
6068
~~~~~~~~~~~~~~~~~

‎tsc/testdata/tests/cases/compiler/importAttributeType1.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ data.version.toFixed();
3434
// @filename: /checkErrors.d.ts
3535
declare module "*.numberValue" with { type: number } {}
3636
declare module "*.objectValue" with { type: { name: string } } {}
37+
declare module "*.css" with { type: `css` } {}
38+
declare module "*.css" with { type: `css${''}` } {}
3739
declare module "*" with { type: "md" | "markdown" } {}
3840
// @filename: /augmentation.ts
3941
export {};

0 commit comments

Comments
 (0)