Skip to content

Commit

Permalink
Fix compiler “Type 'string' is not assignable to type 'PluralRuleName'”
Browse files Browse the repository at this point in the history
I18n.pluralRulesMap keys are variable so “string” wasn’t compatible when the compiler thought we were using fixed string literals

Might be worth another look at `Object.keys()` in future with:

* microsoft/TypeScript#45464
  • Loading branch information
colinrotherham committed Jan 9, 2023
1 parent 3baf82f commit d466765
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/govuk/i18n.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ I18n.prototype.selectPluralFormUsingFallbackRules = function (count) {
* regardless of region. There are exceptions, however, (e.g. Portuguese) so
* this searches by both the full and shortened locale codes, just to be sure.
*
* @returns {PluralRuleName | undefined} The name of the pluralisation rule to use (a key for one
* @returns {string | undefined} The name of the pluralisation rule to use (a key for one
* of the functions in this.pluralRules)
*/
I18n.prototype.getPluralRulesForLocale = function () {
Expand Down Expand Up @@ -262,7 +262,7 @@ I18n.prototype.getPluralRulesForLocale = function () {
* Spanish: European Portuguese (pt-PT), Italian (it), Spanish (es)
* Welsh: Welsh (cy)
*
* @type {Object<PluralRuleName, string[]>}
* @type {Object<string, string[]>}
*/
I18n.pluralRulesMap = {
arabic: ['ar'],
Expand Down Expand Up @@ -350,12 +350,6 @@ I18n.pluralRules = {
/* eslint-enable jsdoc/require-jsdoc */
}

/**
* Supported languages for plural rules
*
* @typedef {'arabic' | 'chinese' | 'french' | 'german' | 'irish' | 'russian' | 'scottish' | 'spanish' | 'welsh'} PluralRuleName
*/

/**
* Plural rule category mnemonic tags
*
Expand Down

0 comments on commit d466765

Please sign in to comment.