From 5cfa86c97b64c0a7e177e258b837956dc1a5a259 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Mon, 10 Feb 2025 22:41:02 -0800 Subject: [PATCH] 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. --- src/normalization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. -- 2.47.3