In my project, I am utilizing Typescript version 3.8.3
alongside
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="395054544c4d585b555c790d17091709144b5a17">[email protected]</a>
.
An issue arises when attempting to create an OrderedMap
using a two-dimensional array for instantiation in Typescript.
let v: OrderedMap<number, string> = OrderedMap([ [ 3, '2' ] ])
For further elaboration and demonstration, check out this example on Codesandbox.io
Upon inspection, it seems that there could be an error in the definition file of the library which results in the following error:
immutable-nonambient.d.ts(1421, 39)
. The specific error message received is:
No overload matches this call.
Overload 1 of 4, '(collection: Iterable<[string | number, string | number]>): OrderedMap<string | number, string | number>', gave the following error.
Argument of type '(string | number)[][]' is not assignable to parameter of type 'Iterable<[string | number, string | number]>'.
The types returned by '[Symbol.iterator]().next(...)' are incompatible between these types.
Type 'IteratorResult<(string | number)[], any>' is not assignable to type 'IteratorResult<[string | number, string | number], any>'.
Type 'IteratorYieldResult<(string | number)[]>' is not assignable to type 'IteratorResult<[string | number, string | number], any>'.
Type 'IteratorYieldResult<(string | number)[]>' is not assignable to type 'IteratorYieldResult<[string | number, string | number]>'.
Type '(string | number)[]' is missing the following properties from type '[string | number, string | number]': 0, 1
Overload 2 of 4, '(obj: { [key: string]: string; }): OrderedMap<string, string>', gave the following error.
Type '(string | number)[]' is not assignable to type 'string'.ts(2769)
immutable-nonambient.d.ts(1421, 39): The expected type comes from this index signature.
A similar issue occurs with Map
. While initializing an empty Map
or OrderedMap
and then performing operations works fine, the problem lies in initializing them via a two-dimensional array.
Interestingly, instantiating using this format: OrderedMap({ 3: '2' })
does not result in compilation errors. However, since I need numeric keys, utilizing the array notation remains the preferred method despite the encountered challenges.