You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Map constructor should accept readonly tuples #29721
TS2345: Argument of type 'readonly [readonly ["1", 1], readonly ["2", 2]]' is not assignable to parameter of type 'readonly [{}, {}][]'.
Type 'readonly ["1", 1] | readonly ["2", 2]' is not assignable to type '[{}, {}]'.
Type 'readonly ["1", 1]' is missing the following properties from type '[{}, {}]': pop, push, reverse, shift, and 6 more.
Playground Link:
Related Issues:
The same issue applies to some libraries on DefinitelyTyped. Maybe readonly tuples should be added to Common mistakes, like arrays?
ark120202Sheetal Nandi (@sheetalkamat) — Can we follow up on this with WeakMap? I’m having the same issue as OP where I’m trying to pass a readonly array of readonly tuples to the WeakMap constructor and getting a TypeError.
interface WeakMapConstructor {
- new <K extends object = object, V = any>(entries?: readonly [K, V][] | null): WeakMap<K, V>;+ new <K extends object = object, V = any>(entries?: readonly (readonly [K, V])[] | null): WeakMap<K, V>;
readonly prototype: WeakMap<object, any>;
}
declare var WeakMap: WeakMapConstructor;
Activity
Fix map constructor to accept readonly tuple
ark120202 commentedon Mar 13, 2019
Sheetal Nandi (@sheetalkamat) the same issue also applies to
WeakMap, could it be fixed as well or should I open a new issue?chharvey commentedon Jan 9, 2021
ark120202 Sheetal Nandi (@sheetalkamat) — Can we follow up on this with
WeakMap? I’m having the same issue as OP where I’m trying to pass a readonly array of readonly tuples to theWeakMapconstructor and getting a TypeError.interface WeakMapConstructor { - new <K extends object = object, V = any>(entries?: readonly [K, V][] | null): WeakMap<K, V>; + new <K extends object = object, V = any>(entries?: readonly (readonly [K, V])[] | null): WeakMap<K, V>; readonly prototype: WeakMap<object, any>; } declare var WeakMap: WeakMapConstructor;