Skip to content

Commit

Permalink
Fix compiler “Type 'number' is not assignable to type 'string'”
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Jan 11, 2023
1 parent b390155 commit b825664
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/govuk/common/normalise-dataset.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function normaliseString (value) {

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

Expand Down
8 changes: 4 additions & 4 deletions src/govuk/i18n.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ I18n.prototype.t = function (lookupKey, options) {
}

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

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

return placeholderValue
Expand Down

0 comments on commit b825664

Please sign in to comment.