Skip to content

Use null instead of Number.NaN in NumberField component #6971

Open
@psirenny

Description

@psirenny

Provide a general summary of the feature here

Replace use of Number.NaN values in the NumberField component with null. This would also enable passing in null to the NumberField which was requested in: #5524.

🤔 Expected Behavior?

The expected behavior is that one must check for null before interacting with values returned by a NumberField. This isn't extra work, because one must already call Number.isNaN() when handling number values.

Why is Number.NaN less desirable? Because:

  • TypeScript doesn't error if a developer forgets to check for NaN
  • TypeScript can't determine whether a NaN check was already performed (extra unnecessary checks)
  • Serializing a NaN to JSON resolves to a null value anyway

😯 Current Behavior

All values from a NumberField component need to be checked for Number.isNaN().

💁 Possible Solution

No response

🔦 Context

I observe most of my team members override onChange and value properties to support null instead. This leads me to think that the DX of the NumberField component isn't quite right. Developers don't expect a number to not be a number and TypeScript doesn't warn about it.

💻 Examples

No response

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions