adobe/react-spectrum

Use `null` instead of `Number.NaN` in NumberField component

Open

#6971 aperta il 28 ago 2024

Vedi su GitHub
 (5 commenti) (9 reazioni) (0 assegnatari)TypeScript (1500 fork)auto 404
enhancementhelp wanted

Metriche repository

Star
 (15.634 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

Guida contributor