From: Ardis Lu Date: Tue, 11 Feb 2025 06:41:02 +0000 (-0800) Subject: Assert non-nullable type instead of using nullish coalesce X-Git-Tag: v0.1.0~57 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=5cfa86c97b64c0a7e177e258b837956dc1a5a259;p=csvio Assert non-nullable type instead of using nullish coalesce There will be undefined `decimal` only if the input to `formatToParts` does not contain a decimal. But there will always be a decimal because the input is hardcoded. The TS language server is not yet intelligent enough to assert it is non-nullable from the hardcoded input, so we need to pass the type hint. Using nullish coalesce results in an uncovered branch which is impossible to test, so it should be removed. --- diff --git a/src/normalization.js b/src/normalization.js index d05377c..b7faa55 100644 --- a/src/normalization.js +++ b/src/normalization.js @@ -1,5 +1,5 @@ // User locale's decimal separator -const DECIMAL_SEPARATOR = Intl.NumberFormat().formatToParts(.1).find(p => p.type === 'decimal')?.value ?? '.'; +const DECIMAL_SEPARATOR = /** @type {Intl.NumberFormatPart!} */(Intl.NumberFormat().formatToParts(.1).find(p => p.type === 'decimal')).value; /** * Convert a string to camelCase.