Skip to content

Disallow 'readonly' modifier in ambient module import attributes types - #64181

Open
erantianantha wants to merge 2 commits into
microsoft:mainfrom
erantianantha:fix/reject-readonly-in-import-attributes-type
Open

Disallow 'readonly' modifier in ambient module import attributes types#64181
erantianantha wants to merge 2 commits into
microsoft:mainfrom
erantianantha:fix/reject-readonly-in-import-attributes-type

Conversation

@erantianantha

Copy link
Copy Markdown

Fixes #64143

Description

Support for import attributes on ambient module declarations (declare module "*.css" with { type: "css" }) was added in #63931. However, readonly modifier on attribute properties was previously accepted without error because checkGrammarModifiers skips readonly for property signatures (as it is normally valid on type literal properties).

This PR:

  1. Adds diagnostic message TS1558: "An import attributes property cannot have a 'readonly' modifier."
  2. Rejects any modifiers (specifically readonly) on property signatures in checkGrammarImportAttributesType.
  3. Adds test cases with reference baselines covering single/multiple readonly attributes and valid non-readonly attributes.

microsoft#64143)

Ambient module import attributes types should not accept the 'readonly' modifier. Adds diagnostic TS1558 ("An import attributes property cannot have a 'readonly' modifier.") and checks for modifiers in checkGrammarImportAttributesType.

Fixes microsoft#64143.
Copilot AI balanced review requested due to automatic review settings September 5, 2026 19:42
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 5, 2026
@typescript-automation typescript-automation Bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Sep 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The modifier check incorrectly reports non-readonly modifiers as readonly.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds validation rejecting readonly properties in ambient-module import attribute types.

Changes:

  • Adds TS1558 and grammar validation.
  • Adds compiler regression coverage and baseline.
File summaries
File Description
grammarchecks.go Validates attribute property modifiers.
diagnosticMessages.json Defines TS1558.
diagnostics_generated.go Registers generated diagnostic.
importAttributeTypeReadonly.ts Adds regression cases.
importAttributeTypeReadonly.errors.txt Records expected diagnostics.
Review details

Files not reviewed (1)

  • tsc/internal/diagnostics/diagnostics_generated.go: Generated file
  • Files reviewed: 4/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread tsc/internal/checker/grammarchecks.go Outdated
Comment on lines +2210 to +2212
if propertySignature.Modifiers() != nil {
return c.grammarErrorOnNode(propertySignature.Modifiers().Nodes[0], diagnostics.An_import_attributes_property_cannot_have_a_readonly_modifier)
}
@erantianantha

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

readonly is accepted in ambient module import attributes types

3 participants