openlang

TypeScript Map initialization with string array entries

I'm creating a Map whose entries each hold an array of strings. How can I declare its type and initialize it together in one statement?

My (naive) attempt was:

    private _rowEntries:Map<string, Array<string>> = {"3": ["sampleA"]};

which produces:

  Module build failed: Error: /Users/arden/Work/controlpanel/src/app/core/rows.service.ts (12,7): Type '{ "3": string[]; }' is not assignable to type 'Map<string, string[]>'.

The conversation continues 2

Follow the reasoning
  1. Permalink
      entryTable: Map<string, string[]> = new Map();

    For inserting entries in a Map:

      entryTable.set("m", ["n", "p"]);

    For reading entries out of a Map:

      entryTable.get(entryKey);// "m" in above case

    Alternatively initialize it directly

      entryTable: Map<string, string[]> = new Map([['m', ['n', 'p']]]);

Other sides of the same question

  1. Typescript Callable Contract

    Why does Typescript accept my function definition even though it differs from the interface signature, yet report a problem w…

    Replies 2Latest activity typescript
  2. Solidity conversion failure from address into uint256

    I made an array containing structs, then attempted to retrieve each account's values from that array. But passing an address…

    Replies 3Latest activity solidity
  3. Is a read-only List<Int> a snapshot?

    List<Int> is a read-only view, not a snapshot. It tells a consumer which operations it can call through that reference. It pr…

    Replies 4Latest activity kotlin