2

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));
}
4
  • Can you please mention the problem you are facing? Commented Sep 11, 2018 at 21:58
  • @ParthS007 I would like to rewrite that function as arrow function... Commented Sep 11, 2018 at 22:00
  • I am trying smt like... with no success: const log = (message: T): IO<void> => new IO(() => console.log(message)); Commented Sep 11, 2018 at 22:01
  • Possible duplicate of What is the syntax for Typescript arrow functions with generics? Commented Sep 11, 2018 at 22:09

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You could try to use:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.