But in your TS example, the code would execute. Not in the Flow example, where it's just an annotation.
There are hacks and other approaches, documented here:
Incorrect. It's a type alias so it uses "type typeof" not "value typeof". It doesn't have the problem that the issue you linked to is about.
https://www.typescriptlang.org/play/#src=function%20getOptio...
Observe the JS output contains no `typeof` and that the type `Options` is considered to be the same as `{ num: number, str: string }` if you hover over it.
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.
function getOptions() { return { num: 42, str: "val" }; }
var __options__ = getOptions();
type Options = typeof __options__;
var options: Options = {
};