diff --git a/tsc/internal/checker/grammarchecks.go b/tsc/internal/checker/grammarchecks.go index 1c7430f2060b9..b49cfa29f6b7a 100644 --- a/tsc/internal/checker/grammarchecks.go +++ b/tsc/internal/checker/grammarchecks.go @@ -2229,7 +2229,7 @@ func (c *Checker) checkGrammarImportAttributesType(attributes *ast.TypeLiteralNo } typeNode := propertySignature.Type - if !ast.IsStringLiteralLikeType(typeNode) { + if !ast.IsLiteralTypeNode(typeNode) || !ast.IsStringLiteral(typeNode.AsLiteralTypeNode().Literal) { return c.grammarErrorOnNode(typeNode, diagnostics.An_import_attributes_property_must_have_a_string_literal_type_annotation) } } diff --git a/tsc/testdata/baselines/reference/compiler/importAttributeType1.errors.txt b/tsc/testdata/baselines/reference/compiler/importAttributeType1.errors.txt index b0c4ca14508fa..a83eac3c223a8 100644 --- a/tsc/testdata/baselines/reference/compiler/importAttributeType1.errors.txt +++ b/tsc/testdata/baselines/reference/compiler/importAttributeType1.errors.txt @@ -7,7 +7,9 @@ Property 'type' is incompatible with index signature. Type '{ name: string; }' is not assignable to type 'string'. /checkErrors.d.ts(2,45): error TS1555: An import attributes property must have a string literal type annotation. -/checkErrors.d.ts(3,33): error TS1555: An import attributes property must have a string literal type annotation. +/checkErrors.d.ts(3,37): error TS1555: An import attributes property must have a string literal type annotation. +/checkErrors.d.ts(4,37): error TS1555: An import attributes property must have a string literal type annotation. +/checkErrors.d.ts(5,33): error TS1555: An import attributes property must have a string literal type annotation. /valid.d.ts(11,38): error TS1555: An import attributes property must have a string literal type annotation. @@ -41,7 +43,7 @@ text.toUpperCase(); data.version.toFixed(); -==== /checkErrors.d.ts (5 errors) ==== +==== /checkErrors.d.ts (7 errors) ==== declare module "*.numberValue" with { type: number } {} ~~~~~~~~~~~~~~~~ !!! error TS2322: Type '{ type: number; }' is not assignable to type 'ImportAttributes'. @@ -55,6 +57,12 @@ !!! error TS2322: Property 'type' is incompatible with index signature. !!! error TS2322: Type '{ name: string; }' is not assignable to type 'string'. ~~~~~~~~~~~~~~~~ +!!! error TS1555: An import attributes property must have a string literal type annotation. + declare module "*.css" with { type: `css` } {} + ~~~~~ +!!! error TS1555: An import attributes property must have a string literal type annotation. + declare module "*.css" with { type: `css${''}` } {} + ~~~~~~~~~~ !!! error TS1555: An import attributes property must have a string literal type annotation. declare module "*" with { type: "md" | "markdown" } {} ~~~~~~~~~~~~~~~~~ diff --git a/tsc/testdata/tests/cases/compiler/importAttributeType1.ts b/tsc/testdata/tests/cases/compiler/importAttributeType1.ts index 641f476e91cad..e9047ef8e59e3 100644 --- a/tsc/testdata/tests/cases/compiler/importAttributeType1.ts +++ b/tsc/testdata/tests/cases/compiler/importAttributeType1.ts @@ -34,6 +34,8 @@ data.version.toFixed(); // @filename: /checkErrors.d.ts declare module "*.numberValue" with { type: number } {} declare module "*.objectValue" with { type: { name: string } } {} +declare module "*.css" with { type: `css` } {} +declare module "*.css" with { type: `css${''}` } {} declare module "*" with { type: "md" | "markdown" } {} // @filename: /augmentation.ts export {};