adobe/react-spectrum

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

Open

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

在 GitHub 查看
 (5 评论) (9 反应) (0 负责人)TypeScript (1,500 fork)auto 404
enhancementhelp wanted

仓库指标

Star
 (15,634 star)
PR 合并指标
 (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

贡献者指南