Skip to content

Strictly-typed option value for typed select, radio and checkbox inputs #59923

@martinboue

Description

@martinboue

Which @angular/* package(s) are relevant/related to the feature request?

forms

Description

Option values for selectable input (select, radio or checkbox) should be type checked when using typed form control.

Proposed solution

value attribute should have the same type as its form control value.

If type does not match, we would have a Typescript error.

Example

Let's say I have a form control with the following type:

country: FormControl<string>

and the following template:

<select [formControl]="country">
  <!-- Valid type -->
  <option value="France">
  <!-- Incorrect types -->
  <option [value]="0"> 
  <option [value]="true">
</select>

I want option 0and true to fail to compile, because they do not match the type string.

Same principle would apply to <input type="radio" /> and <input type="checkbox" />.

Alternatives considered

If not doable, could be specific to Angular Material components.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions