Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tsc/internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,13 @@ func (c *Checker) checkGrammarImportAttributesType(attributes *ast.TypeLiteralNo
return c.grammarErrorOnNode(member, diagnostics.An_import_attributes_type_may_only_contain_property_signatures)
}
propertySignature := member.AsPropertySignatureDeclaration()
if modifiers := propertySignature.Modifiers(); modifiers != nil {
for _, modifier := range modifiers.Nodes {
if modifier.Kind == ast.KindReadonlyKeyword {
return c.grammarErrorOnNode(modifier, diagnostics.An_import_attributes_property_cannot_have_a_readonly_modifier)
}
}
}
if propertySignature.Type == nil {
return c.grammarErrorOnNode(member, diagnostics.An_import_attributes_property_must_have_a_type_annotation)
}
Expand Down
4 changes: 4 additions & 0 deletions tsc/internal/diagnostics/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,10 @@
"category": "Error",
"code": 1557
},
"An import attributes property cannot have a 'readonly' modifier.": {
"category": "Error",
"code": 1558
},

"The types of '{0}' are incompatible between these types.": {
"category": "Error",
Expand Down
4 changes: 4 additions & 0 deletions tsc/internal/diagnostics/diagnostics_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/otherModifierError.d.ts(1,31): error TS1070: 'public' modifier cannot appear on a type member.
/readonlyError.d.ts(1,31): error TS1558: An import attributes property cannot have a 'readonly' modifier.
/readonlyError.d.ts(6,32): error TS1558: An import attributes property cannot have a 'readonly' modifier.


==== /readonlyError.d.ts (2 errors) ====
declare module "*.css" with { readonly type: "css" } {
~~~~~~~~
!!! error TS1558: An import attributes property cannot have a 'readonly' modifier.
const stylesheet: CSSStyleSheet;
export default stylesheet;
}

declare module "*.json" with { readonly type: "json", readonly kind: "data" } {
~~~~~~~~
!!! error TS1558: An import attributes property cannot have a 'readonly' modifier.
const data: any;
export default data;
}

==== /otherModifierError.d.ts (1 errors) ====
declare module "*.svg" with { public type: "svg" } {
~~~~~~
!!! error TS1070: 'public' modifier cannot appear on a type member.
const content: string;
export default content;
}

==== /valid.d.ts (0 errors) ====
declare module "*.txt" with { type: "text" } {
const text: string;
export default text;
}

27 changes: 27 additions & 0 deletions tsc/testdata/tests/cases/compiler/importAttributeTypeReadonly.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @strict: true
// @module: preserve
// @noEmit: true
// @noTypesAndSymbols: true

// @filename: /readonlyError.d.ts
declare module "*.css" with { readonly type: "css" } {
const stylesheet: CSSStyleSheet;
export default stylesheet;
}

declare module "*.json" with { readonly type: "json", readonly kind: "data" } {
const data: any;
export default data;
}

// @filename: /otherModifierError.d.ts
declare module "*.svg" with { public type: "svg" } {
const content: string;
export default content;
}

// @filename: /valid.d.ts
declare module "*.txt" with { type: "text" } {
const text: string;
export default text;
}