1

I have the following function in TS, I would like to rewrite it to an arrow function.

I tried with no result. Could you please point me the right direction? Thanks!

function log<T>(message: T): IO<void> {
  return new IO(() => console.log(message));
}
Radex
  • 7,815
  • 23
  • 54
  • 86
  • Can you please mention the problem you are facing? – ParthS007 Sep 11 '18 at 21:58
  • @ParthS007 I would like to rewrite that function as arrow function... – Radex Sep 11 '18 at 22:00
  • I am trying smt like... with no success: const log = (message: T): IO => new IO(() => console.log(message)); – Radex Sep 11 '18 at 22:01
  • Possible duplicate of [What is the syntax for Typescript arrow functions with generics?](https://stackoverflow.com/questions/32308370/what-is-the-syntax-for-typescript-arrow-functions-with-generics) – JKillian Sep 11 '18 at 22:09

2 Answers2

3

Your attempt was close, but you forgot to include the generic argument declaration in front of the arrow function parameters. Try something like this:

const log = <T>(message: T): IO<void> =>
   new IO(() => console.log(message));

If you're working in a .tsx file, you may need to do something a little more complex to make it work.

JKillian
  • 18,061
  • 8
  • 41
  • 74
0

You could try to use:

const log = <T>(message: T): IO<void> => new IO(() => console.log(message));
GibboK
  • 71,848
  • 143
  • 435
  • 658