GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(forms): enforce nullable types for signal form number and date inputs by JeanMeche · Pull Request #72231 · angular/angular

Conversation

@JeanMeche

@JeanMeche JeanMeche commented Nov 26, 2026

Copy link
Copy Markdown
Member

Draft PR to test TGP impact of enforcing invariant nullable types on native numeric and date [formField] bindings.

Uses the same invariant structural union check in TcbNativeFieldOp that <input type="text"> already uses:

  • number, datetime-local: Field<string> | Field<number | null>
  • range: Field<string> | Field<number> | Field<number | null>
  • date, month, time, week: Field<string> | Field<number> | Field<Date | null>

Fixes #72230

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

michael-small and MeAkib reacted with heart emoji
All reactions
  • ❤️ 2 reactions
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Nov 26, 2026
@ngbot ngbot Bot added this to the Backlog milestone Nov 26, 2026
@JeanMeche JeanMeche mentioned this pull request Nov 26, 2026
docs(forms): show nullable number and Date models in signal forms guides #72217
Open
@angular-robot angular-robot Bot added the area: forms label Nov 26, 2026
@JeanMeche
fix(forms): enforce nullable types for signal form number and date in…
7bacdee
…puts

Use an invariant structural union check in TcbNativeFieldOp for numeric and date inputs, matching the existing check used for text inputs.

Previously, these inputs used a covariant read-only check that allowed non-nullable Field<number> on <input type="number"> and Field<Date> on <input type="date">, even though clearing the input writes null to the model signal at runtime.

- number, datetime-local: string | number | null (invariant)
- range: string | number | number | null (invariant)
- date, month, time, week: string | number | Date | null (invariant)

Fixes angular#72230
@JeanMeche
JeanMeche force-pushed the fix/form-field-nullable-number-date branch from 8efa053 to 7bacdee Compare November 26, 2026 13:39
@JeanMeche JeanMeche changed the title fix(compiler): enforce nullable types for signal form number and date inputs fix(forms): enforce nullable types for signal form number and date inputs Nov 26, 2026
@JeanMeche
JeanMeche requested a review from leonsenft November 26, 2026 13:43
@JeanMeche
JeanMeche marked this pull request as ready for review November 26, 2026 13:53
@JeanMeche JeanMeche added the action: global presubmit The PR is in need of a google3 global presubmit label Nov 26, 2026
@SkyZeroZx

SkyZeroZx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Just as a note the age/rating example is still using non nullable numbers and isn't covered by #72217

angular/adev/src/content/guide/forms/signals/validation.md

Lines 181 to 216 in 63fa515

```angular-ts
import {Component, signal} from '@angular/core';
import {form, FormField, min, max} from '@angular/forms/signals';
@Component({
selector: 'app-age-form',
imports: [FormField],
template: `
<form novalidate>
<label>
Age
<input type="number" [formField]="ageForm.age" />
</label>
<label>
Rating (1-5)
<input type="number" [formField]="ageForm.rating" />
</label>
</form>
`,
})
export class AgeFormComponent {
ageModel = signal({
age: 0,
rating: 0,
});
ageForm = form(this.ageModel, (schemaPath) => {
min(schemaPath.age, 18, {message: 'You must be at least 18 years old'});
max(schemaPath.age, 120, {message: 'Please enter a valid age'});
min(schemaPath.rating, 1, {message: 'Rating must be at least 1'});
max(schemaPath.rating, 5, {message: 'Rating cannot exceed 5'});
});
}
```

I checked it against the base commit and this PR: it compiles before the change, but both [formField] bindings now fail with TS2322.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MeAkib

MeAkib commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Just as a note the age/rating example is still using non nullable numbers and isn't covered by #72217

angular/adev/src/content/guide/forms/signals/validation.md

Lines 181 to 216 in 63fa515

```angular-ts
import {Component, signal} from '@angular/core';
import {form, FormField, min, max} from '@angular/forms/signals';
@Component({
selector: 'app-age-form',
imports: [FormField],
template: `
<form novalidate>
<label>
Age
<input type="number" [formField]="ageForm.age" />
</label>
<label>
Rating (1-5)
<input type="number" [formField]="ageForm.rating" />
</label>
</form>
`,
})
export class AgeFormComponent {
ageModel = signal({
age: 0,
rating: 0,
});
ageForm = form(this.ageModel, (schemaPath) => {
min(schemaPath.age, 18, {message: 'You must be at least 18 years old'});
max(schemaPath.age, 120, {message: 'Please enter a valid age'});
min(schemaPath.rating, 1, {message: 'Rating must be at least 1'});
max(schemaPath.rating, 5, {message: 'Rating cannot exceed 5'});
});
}
```

I checked it against the base commit and this PR: it compiles before the change, but both [formField] bindings now fail with TS2322.

Good catch, thanks @SkyZeroZx. I checked the rest of the guides and found a few more snippets that bind a non-nullable number model to <input type="number">:

  • guide/forms/signals/validation.md: the age/rating min()/max() example
  • guide/forms/signals/form-logic.md: the Order example (twice), the Age example and the Inventory example
  • reference/errors/NG8022.md: both examples

Two of them also compare the value with < in a when condition, which then needs a null fallback such as (valueOf(p.age) ?? 0) < 18.

@JeanMeche I can send a follow-up docs PR for these once #72217 lands, unless you'd rather include them in this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@leonsenft leonsenft Awaiting requested review from leonsenft

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

action: global presubmit The PR is in need of a google3 global presubmit area: compiler Issues related to `ngc`, Angular's template compiler area: forms

Projects

None yet

Milestone

Backlog

Development

Successfully merging this pull request may close these issues.

Signal Forms: [formField] should require nullable types on numeric and date inputs

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@JeanMeche @SkyZeroZx @MeAkib
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.