Skip to content

readonly is accepted in ambient module import attributes typesΒ #64143

Description

@camc314

πŸ”Ž Search Terms

readonly import attributes, readonly ambient module, readonly pattern ambient module, module declaration attributes

πŸ•— Version & Regression Information

⏯ Playground Link

N/A

πŸ’» Code

declare module "*.css" with { readonly type: "css" } {
  const stylesheet: CSSStyleSheet;
  export default stylesheet;
}

πŸ™ Actual behavior

TypeScript accepts readonly on a property in an ambient module’s import attributes type.

Other modifiers such as private and declare are rejected by the ordinary type-member modifier checks, but readonly is valid on property signatures and is therefore accepted here.

It is unclear what readonly means for import attribute matching, declaration identity, specificity, or merging:

declare module "*.css" with { type: "css" } {
  export const mutable: true;
}

declare module "*.css" with { readonly type: "css" } {
  export const readonly: true;
}

Should these declarations describe identical import attributes types and merge, or should they be distinct?

πŸ™‚ Expected behavior

readonly should be rejected in an import attributes type because these properties describe module-resolution attributes rather than mutable values, and the modifier has no apparent role in matching.

Alternatively, if readonly is intentionally supported, its effect on identity, merging, assignability, and specificity should be clarified.

Additional information about the issue

The import attributes grammar check added in #63931 validates property kind, optionality, name, and string-literal value type, but does not validate readonly.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions