W
W
Wynell_ru2020-08-12 15:46:43
typescript
Wynell_ru, 2020-08-12 15:46:43

How to fix this error in TypeScript?


This overload signature is not compatible with its implementation signature.


The code:
function printInc(a: number): void;
function printInc(a: string): void {
    switch (typeof a) {
        case 'string':
            console.log(a + ' plus one');
            break;
        case 'number':
            console.log(a + 1);
            break;
    }
}


URL:
https://www.typescriptlang.org/play?ssl=1&ssc=22&p...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-08-12
@Wynell_ru

function printInc(a: string | number): void {
  switch (typeof a) {
    case 'string':
      console.log(a + ' plus one');
      break;
    case 'number':
      console.log(a + 1);
      break;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question