Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difficulty using GenType with include and functors #7156

Open
jmagaram opened this issue Nov 11, 2024 · 1 comment
Open

Difficulty using GenType with include and functors #7156

jmagaram opened this issue Nov 11, 2024 · 1 comment

Comments

@jmagaram
Copy link
Contributor

I am working on and off with a hobby project using ReScript and keep running into problems using GenType whenever include and functors are used. Considering that there is a goal to improve GenType in the future - such as emitting .d.ts files - I want to include this general issue. I've filed lots of similar bugs in the past, and some specific problems get fixed. But for me the big picture is that it does not "just work", at all. There are always gotchas and complications. Here is my repo project.

https://github.com/jmagaram/functors

Why am I using functors? I'm a big fan of wrapping basic types like int and string inside dedicated types like Age, DocumentTitle, PersonName, etc. And for these basic types, I want a bunch of basic utility functions that handle construction with validation, sorting, equality, and serialization. This is a perfect use for functors because it allows me to reduce code duplication. I need GenType for these wrapped types because I plan to integrate with a TypeScript project. If I can't access these core types from TypeScript then I can't use ReScript.

In the sample project, you'll see a module called Primitive which has a functor to make each specific wrapped type. And then ShortStringA, ShortStringB, ShortStringC, and ShortStringD are my attempts to actually use it. None of the example solutions works. The closest solution is ShortStringB but this requires me to hand-write a repetitive .resi file for every specific type I build. I can't seem to include the type definition and get the @genType annotations to follow through.

The documentation on all this is poor. Do the genType annotations work inside a .resi? What if they are in both the .resi and the .res files? Does it work with functors and include? I've had to do a lot of frustrating trial and error.

@cometkim
Copy link
Member

It is true that genType does not work well at the module function level. Some of that is simply because it hasn't been implemented, and there is no valid workaround to be documented today.

My goal is very same as what you mentioned, making the genType as first-class feature. In other words, it should just work.

After the milestone, ideally, even no additional documentation is needed for the feature except only configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants