DEV Community· SIGNUM HQ·· 3 小時前AI 評分38
小型 TypeScript 模型中的缺失值不等於零
Missing values are not zero in a small TypeScript model
AI 導讀
這個小型 TypeScript 模型把缺失讀數與觀察到的零值區分開,避免兩者都轉成零後悄然改變平均值或條件判斷。缺失狀態應在解析、儲存和呈現時保留;示例屬 AI 生成設計示例,並非 SIGNUM HQ 已部署的程式碼。
正文
This AI-generated design example is illustrative and does not describe deployed SIGNUM HQ code. A feed that is unavailable and an observed zero are different states. Converting both to zero can silently change an average or a condition.
type Reading = { status: 'observed'; value: number } | { status: 'missing' };
function observedValue(r: Reading): number | null {
return r.status === 'observed' ? r.value : null;
}
Consumers must decide how to display or exclude missing observations. Keep the distinction through parsing, storage and presentation rather than trying to recover it after formatting.
來源:DEV Community · dev.to