Skip to content

Map constructor should accept readonly tuples #29721

Closed
@ark120202

Description

@ark120202

TypeScript Version: 3.4.0-dev.20190202

Search Terms:

Readonly tuple, map, as const, const context

Code

const pairs = [['1', 1], ['2', 2]] as const
new Map(pairs);

Expected behavior:

No error

Actual behavior:

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?

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFix AvailableA PR has been opened for this issueFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions