Convert `namespace$type` to `namespace.type`
aminya opened this issue · 3 comments
It would be nice if the type namespaces could be converted instead of leaving them as is.
For example,
let editor: atom$TextEditor
can be converted to
import * as atom from "atom"
let editor: atom.TextEditor
Optionally in a config file, a map of the namespaces to the modules could be defined by the user, so flow-to-ts knows where the
{
"namespace1": "some_module",
"namespace2": "./src/some_file.js"
}
Modules can be written as-is.
import * as namespace1 from "some_module"
The files should be reletivized using path.relative
:
import * as file "result_of_path.relative(__fileName, file_in_the_config)"
I've seen a number of libdefs from flow-typed using this convention. I was hoping to replace files in flow-typed/npm
with files from DefinitelyTyped. Are there not types for atom
in DefinitelyTyped or is there a use case other than libdefs where this functionality would be useful?
In some cases like moment$Moment
, the global type is used to avoid doing a namespace import which brings in the whole module when all we really wanted was the type. @aminya how would you feel if flow-to-ts
generated the following output:
import type {TextEditor} from "atom"
let editor: TextEditor
Yes, that works for me. I think my suggestion in the above generalizes the problem. I am not fully familiar with all the semantics of $
in Flow, but I think what I suggested covers all the cases (especially because it is configurable)? If not, your suggestion works for me as well!