Make Intl locales arrays readonly #56513
Labels
Bug
A bug in TypeScript
Domain: lib.d.ts
The issue relates to the different libraries shipped with TypeScript
Good First Issue
Well scoped, documented and has the green light
Help Wanted
You can do this
Milestone
⚙ Compilation target
Any
⚙ Library
intl.d.ts
Missing / Incorrect Definition
The
locales
array should be typed as a readonly array in Intl constructors and methods.Currently they typed as normal arrays which causes a type error when passing a readonly array such as
navigator.languages
.Resulting in the following:
Argument of type 'readonly string[]' is not assignable to parameter of type 'string | string[] | undefined'. The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.(2345)
There was a previous PR #50135 that fixed it for one particular call site. However there are still several instances that also have this issue:
TypeScript/src/lib/es2016.intl.d.ts
Line 12 in d4fbc9b
TypeScript/src/lib/es2018.intl.d.ts
Lines 33 to 36 in d4fbc9b
TypeScript/src/lib/es2020.intl.d.ts
Line 203 in d4fbc9b
TypeScript/src/lib/es2020.intl.d.ts
Line 226 in d4fbc9b
TypeScript/src/lib/es2021.intl.d.ts
Line 128 in d4fbc9b
TypeScript/src/lib/es2021.intl.d.ts
Line 146 in d4fbc9b
TypeScript/src/lib/es2022.intl.d.ts
Line 74 in d4fbc9b
TypeScript/src/lib/es2022.intl.d.ts
Line 88 in d4fbc9b
Sample Code
Documentation Link
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#using_the_browsers_preferred_language
The text was updated successfully, but these errors were encountered: