V
V
Vladimir Golub2021-01-21 15:52:24
typescript
Vladimir Golub, 2021-01-21 15:52:24

How to solve Map and async/await "No overload matches this call" problem?

There is a function that returns certain content,

public async getContent() {

    const a = new Map([
      [
        'AA',
        new Map([
          ['desc', [await this.i18n.t('Hello'), await this.i18n.t('Hello')]],
        ])
      ]
    ]);


it works, but as soon as I add one more pair in internal Map there is an error?

public async getContent() {

    const a = new Map([
      [
        'AA',
        new Map([
          ['desc', [await this.i18n.t('Hello'), await this.i18n.t('Hello')]],
          ['a', 'b']
        ])
      ]
    ]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2021-01-21
@RazerVG

Specify Explicitly a Generic for the Internal Map

public async getContent() {

    const a = new Map([
      [
        'AA',
        new Map<string, string | string[]>([
          ['desc', [await this.i18n.t('Hello'), await this.i18n.t('Hello')]],
          ['a', 'b']
        ])
      ]
    ]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question