S
S
sergeyviktorovich2021-12-27 12:40:12
typescript
sergeyviktorovich, 2021-12-27 12:40:12

What's wrong with the void operator?

Promises must be handled appropriately or explicitly marked as ignored with the `void` operator.
    167 |   methods: {
    168 |     openUnit(it: string):void {
  > 169 |       this.$router.push(`/unit/${it}`)
        |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    170 |     }
    171 |   },
    172 |   async beforeMount():Promise<void> {

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2021-12-27
@Aetae

An ESlint rule that doesn't like floating Promises.
It wants you to do one of the following:

methods: {
  openUnit(it: string):void {
    void this.$router.push(`/unit/${it}`);
  }
}

methods: {
  openUnit(it: string) {
    return this.$router.push(`/unit/${it}`);
  }
}

methods: {
  async openUnit(it: string) {
    await this.$router.push(`/unit/${it}`);
  }
}

Like, if the Promise is not explicitly processed, you may have made a mistake and went to execute the code without waiting for its permission.

V
Vasily Bannikov, 2021-12-27
@vabka

He wants you to write like this:
void this.$router.push(`/unit/${it}`);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question