Skip to content

Angular should report an error when creating a readonly input #45186

Open
@jelbourn

Description

@jelbourn

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

No

Description

The @Input decorator tells Angular that a property can be written to in a template. However, if you add the @Input decorator to a readonly property, no error is reported. We should report an error, since mixing these two concepts doesn't make sense.

@Component(...)
export class UserProfile {
  @Input() readonly name: string;
}

At time of writing, there are 37 occurrences of this in Google we'd have to clean up. Not sure if this is prevalent enough to warrant an ng update schematic (which would probably just remove readonly).

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-ivy-j8vlxf?file=src%2Fapp%2Fhello.component.ts


EDIT (April 2024): This does not apply to signal-based inputs

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: compilerIssues related to `ngc`, Angular's template compilerbreaking changescompiler: template type-checking

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions