Hacker News new | ask | show | jobs
by silviogutierrez 3305 days ago
I don't understand. In your transpiled code, getOptions is clearly being called in JS.

In flow, getOptions() wouldn't be in the transpiled code at all.

Imagine the body of getOptions as an extremely expensive computation. Some prime calculation. But you only want its return type. In flow comments, you can get it.

In the approach of your snippet, you could get it, but it will execute the full function with the full price.

2 comments

My bad, I thought you were referring to `typeof` being the code that still executes. Now I read that tweet more carefully and noticed the `getOptions()` call is in a comment. A strange feature that I suppose is useful when dealing with complex anonymous types, though in my experience such complex types tend to be named.
The minifier would get rid of the __options__, and also the function getOptions because both are not used in the resulting code. You need a minifier in any serious project.
It wouldn't. getOptions() could have side effects that we want to run. Imagine inside of getOptions we have a prompt() call to fill in some of the options...