Skip to content

Commit b694c4b

Browse files
Fix compiler “Type 'number' is not assignable to type 'string'”
1 parent d481700 commit b694c4b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/govuk/common/normalise-dataset.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function normaliseString (value) {
3434

3535
// Empty / whitespace-only strings are considered finite so we need to check
3636
// the length of the trimmed string as well
37-
if (trimmedValue.length > 0 && isFinite(trimmedValue)) {
37+
if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {
3838
return Number(trimmedValue)
3939
}
4040

src/govuk/i18n.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ I18n.prototype.t = function (lookupKey, options) {
3333
}
3434

3535
// If the `count` option is set, determine which plural suffix is needed and
36-
// change the lookupKey to match. We check to see if it's undefined instead of
36+
// change the lookupKey to match. We check to see if it's numeric instead of
3737
// falsy, as this could legitimately be 0.
38-
if (options && typeof options.count !== 'undefined') {
38+
if (options && typeof options.count === 'number') {
3939
// Get the plural suffix
4040
lookupKey = lookupKey + '.' + this.getPluralSuffix(lookupKey, options.count)
4141
}
@@ -87,8 +87,8 @@ I18n.prototype.replacePlaceholders = function (translationString, options) {
8787
}
8888

8989
// If the placeholder's value is a number, localise the number formatting
90-
if (typeof placeholderValue === 'number' && formatter) {
91-
return formatter.format(placeholderValue)
90+
if (typeof placeholderValue === 'number') {
91+
return formatter ? formatter.format(placeholderValue) : placeholderValue.toString()
9292
}
9393

9494
return placeholderValue

0 commit comments

Comments
 (0)