Cannot export a type from inside a functor call
TomiS opened this issue · comments
At least in flow, exporting a type inside a functor call does not generate gentype output. Is this intended?
// To reproduce, define some functor that requires type(s) as parameter
module type Config = {
type inputType
}
module Make = (Config: Config) => {
type inputType = Config.inputType
}
// Works as expected, if export is done outside of the functor
export type myType = [ #var1 | #var2 ]
module Foo1 = Make({
type inputType = myType
})
// Does not generate any .gen output.
module Foo2 = Make({
export type inputType = [ #var1 | #var2 ]
})
It'd be very nice if the latter example worked (if it's not techically really hard/impossible) as it does not pollute the root module namespace.
It seems if I try to refer to Foo2.inputType
from another file, the callsite gentype code is generated just nice. Just the export side is missing
Consider that annotations (export == @genType annotation) are not propagated by the type checker.
This means that the argument to Foo gets lost into the functor application.
If you declare the argument module M separately and then pass it to the functor, is what's generated useful for what you had in mind?
Did you mean this?
module FooInput = {
export type myType = [ #var1 | #var2 ]
}
module Foo1 = Make({
module Input = FooInput
})
So if it's so that the type that's defined inside a functor does not exist after the functor application, then this is indeed probably the second best alternative.
Thanks for the info.