Hacker News new | past | comments | ask | show | jobs | submit login

You don't even need to do this much, you can just invoke the function and let the return type be inferred.

  const inferred = (() => "Hello")() // Inferred as "string"

If you really don't want to use an IIFE because you don't like the "()" at the end, you can just:

  const myFn = () => { switch(...) }
  const inferred = myFn()



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: