Skip to content

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

In review

Description

@JeanMeche

Description

Currently, TcbNativeFieldOp type-checks [formField] on <input type="number">, <input type="datetime-local">, <input type="date">, <input type="month">, <input type="time">, and <input type="week"> with a covariant read-only check (string | number | null / string | number | Date | null).

Because the check is covariant, non-nullable fields such as form(signal(3)) (Field<number>) on <input type="number"> or form(signal(new Date())) (Field<Date>) on <input type="date"> compile without error:

@Component({
  imports: [FormField],
  template: `
    <input type="date" [formField]="f" />
    <input type="number" [formField]="f2" />
  `,
})
export class App {
  f = form(signal(new Date()));
  f2 = form(signal(3));
}

However, at runtime (getNativeControlValue in packages/forms/signals/src/directive/native.ts), clearing the input sets the signal value to null:

  • <input type="number"> / <input type="datetime-local">: returns null when element.value === "".
  • <input type="date"> / <input type="month"> / <input type="time"> / <input type="week">: returns element.valueAsDate (null when cleared).

This violates type soundness by writing null into a WritableSignal<number> or WritableSignal<Date>. It is also inconsistent with <input type="text">, which already uses an invariant structural union check ({ (): string; set: (v: string) => void; } | { (): number | null; set: (v: number | null) => void; }) to reject Field<number> and Field<string | null>.

Proposed solution

Use the same invariant structural union check in TcbNativeFieldOp for:

  • number, datetime-local: string | number | null
  • range: string | number | number | null (cannot be cleared to null via browser UI)
  • date, month, time, week: string | number | Date | null

(Note: number on date/month/time/week returns element.valueAsNumber which is NaN when cleared, not null.)

Activity

  1. added this to the needsTriage milestone on Nov 26, 2026
  2. added a commit that references this issue on Nov 26, 2026
    7bacdee
  3. moved this from In Progress to In Review in Signal Formson Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions