-
Notifications
You must be signed in to change notification settings - Fork 44
Exposing module types #64
Comments
@MarcelCutts What's in |
I had a quick play - a functor is not required. Simplified test case below: module A = {
type user = {name: string};
};
[@genType]
type b = A.user; Generated flow type: export opaque type b = A_user; Where "A_user" cannot be resolved. |
Adding one more report received for the same underlying issue : "there's no decent way to tag an included modules' type with [@genType]". |
There's some annotation real estate planned but not used yet. Perhaps the annotation of modules could be used to mean that all the items within are annotated. The real estate is a bit crowded though, as the annotation on modules could also be used to indicate grouping elements as objects: #63. |
@MarcelCutts, quite a lot of re-thinking and re-factoring later, see: It addresses your little repro -- not sure exactly what the original problem generates, but can take a look if there are more details. |
I've been watching the progress, absolutely amazing work! This solution does indeed tackle the simplified problem, but my original use-case still doesn't quite work as intended. Summary
Now we can do in-file static module declarations great, but it turns out functors are required and can't be subverted in these external libraries. Test case A.re module type AConfig = {type configType;};
module A = {
module Make = (Conf: AConfig) => {
type a = Conf.configType;
};
};
module B =
A.Make({
type configType = int;
});
[@genType]
type c = B.a; A.re.js import type {a as B_a} from './B.re';
export opaque type c = mixed; However Again, I want to emphasis a strong appreciation for the effort on this project. It's fantastic. 👍 |
…lication. Handles the functor application example in #64.
For additional context, I have dug up the "in anger" source from The |
After this 9d99c5e, and the previous commit, it might be worth having another go and see if a more complex repro is required or the one provided was representative. The last repro goes through now. |
No luck yet but it feels tantalisingly close. Our original use case is still not quite good to go. module GetUser = [%graphql
{| query getUser { user { firstName, lastName, telephone } }|}
];
module GetUserQuery = ReasonApollo.CreateQuery(GetUser);
[@genType]
type responseType = GetUser.t; import type {t as MT_Ret_t} from './MT_Ret.re';
export opaque type GetUser_t = mixed;
export type responseType = GetUser_t; (Where MT_Re.re is not a real separate file but a nested module) I haven't quite been able to figure out why this one doesn't work but my test case (even when split across files) work great. I will spend a bit of effort trying to understand and create a suitable trimmed down test case. |
Btw there’s a little trick: generate the .rei interface automatically, and then look at what the generated types look like. |
First-class modules are only supported in a simple form, where in `(val (module A): ModType)` the restriction is that `ModType` is a module type identifier, and noth a path. Also support module include: `module N = {include M}`. This might help with #64.
In case it helps: 57628ea for (some) first-class modules, and module include. |
It works! 🎉 module GetUser = [%graphql
{| query getUser { user { firstName, lastName, telephone } }|}
];
module GetUserQuery = ReasonApollo.CreateQuery(GetUser);
[@genType]
type responseType = GetUser.t; now becomes export type GetUser_MT_Ret_t = {|+user: {|
+firstName: string,
+lastName?: string,
+telephone: number
|}|};
export type GetUser_t = GetUser_MT_Ret_t;
export type responseType = GetUser_t; And everything is fantastic. Thanks again for the diligent effort on this. |
Awesome, this was fun. Thanks for the perseverance. |
A double ast transform (ppx plus genType), is probably the most complicated way one could go about generating an object with 3 fields. |
Since everything is resolved I'm happy to close this issue ✅ |
I've been experimenting with mixing ReasonML and regular JS to provide a solid foundation across side effects.
One thing that I would find amazingly useful is being able to run
genType
on types within instantiated modules so I can expose those to regularflow
d componentsA reason-apollo example
Here responseType ends up being
where
GetUser_t
cannot be resolved.Is this something that's on the roadmap? Or is it one of those things that is actually rather difficult?
The text was updated successfully, but these errors were encountered: