adobe/react-spectrum

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

开放

#6,971 创建于 2024年8月28日

 (5 条评论) (9 个反应) (0 位负责人)TypeScript (1,500 个派生)auto 404
enhancementhelp wanted

仓库指标

星标
 (15,634 个星标)
PR 合并指标
 (平均合并 8天 2小时) (30 天内合并 80 个 PR)

描述

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

贡献者指南