]> git.ardis.lu - csvio/commitdiff
Assert non-nullable type instead of using nullish coalesce
authorArdis Lu <ardisglu@gmail.com>
Tue, 11 Feb 2025 06:41:02 +0000 (22:41 -0800)
committerArdis Lu <ardisglu@gmail.com>
Tue, 11 Feb 2025 06:41:02 +0000 (22:41 -0800)
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

index d05377c91867aa7f185c59ec2f404462e6a8c13c..b7faa553294747605266ce8619b22916543a0d86 100644 (file)
@@ -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.
This page took 0.040171 seconds and 4 git commands to generate.