-
Notifications
You must be signed in to change notification settings - Fork 30
Can't use genType #128
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
Comments
Hmm, IIRC this was recently fixed. What ReScript compiler version are you on? |
In my package.json I see |
Could you try |
Same problem |
Did a clean, verified with
|
I have the same problem with a different package. Does the author of the package need to put @gentype everywhere or is the compiler supposed to handle this? |
Not sure what the issue is here. |
I'll try again with a repo scenario but your example doesn't look like what I'm talking about - just reading on my phone. Array isn't a problem because it is built in. But Error.t and Null.t are not so typescript doesn't know where to find them. . Could you clarify if that gentyoe doc comment is still true that the library author must generate and publish the .gen files with their package? |
Just to be clear I'm trying to use Core in another project when it lives in the node_modules folder. |
Repo scenarios here https://github.com/jmagaram/core-gentype |
There was an issue to explore that scenario: picking up annotations from dependencies. But there was no concrete work on that. |
@jmagaram I should look for the analogous discussion in the genType repo, where exactly these kinds of issues were discussed.
|
I don't know how helpful I can be with this. I'll read whatever you send my way. I tried getting it to work with Core by removing Core from But whenever I try to use them via
to this. I think the
There is a problem with |
So to summarize: the path generated is correct but there is no file at that path? Assuming this is all true (please confirm in case) it would be useful to just add the file by hand and check that everything works. If everything works, then it's just a matter to make sure that the file is there. |
All scenarios require Now I have it set up with If you access the code with full path, like But if we want to access things through the root module Error: {
include module type of Core__Error
} = {
include Core__Error
} But if you access the library through the @genType
let makeError1: unit => RescriptCore.Error.t = () => RescriptCore.Error.make("wow")
@genType
let makeError2: unit => Core__Error.t = () => Core__Error.make("wow") This is some of the javascript. // tslint:disable-next-line:no-var-requires
const OpenCoreBS = require('./OpenCore.bs');
import type {t as Core__Error_t} from '@rescript/core/src/Core__Error.gen';
import type {t as Error_t} from './Error.gen';
import type {t as Null_t} from './Null.gen';
export const makeError1: () => Error_t = OpenCoreBS.makeError1;
export const makeError2: () => Core__Error_t = OpenCoreBS.makeError2; I'm running into this same problem on a package I built for my personal use. Maybe there should be some way to do something like |
I don't understand the underlying problem. Something about the compiler not realizing that RescriptCore.Error.t is the same thing as Core__Error.t. |
I think a couple of different aspects have been identified, and can be explored further separately.
It's important to separate the two aspects and dig deeper to get clarity. For 1, there's something new now: in v11, genType will not generate conversion functions (a.k.a. additional code) in the .gen.tsx files. That means, it becomes conceivable to add a global config flag equivalent to adding the For 2, we need to cut down the problem. It should be possible to have a tiny example with 1 or 2 files with a couple of lines each to illustrate the issue. It might be that those files need to be in a dependency, or perhaps one can repro with just using a single project. One needs to try. So it's about: start with an example of broken behaviour and cut it down more and more until it becomes completely clear what the underlying issue is. |
I created a simpler repro example inside the project in https://github.com/jmagaram/core-gentype (1) If we use (2) If the developer attempts to put (3) If we duplicate the type inside the wrapper, like (4) I think there is an option to copy the entire implementation of every module into the wrapper module using that (5) Rename all the modules from (6) Some new compiler feature or |
Let's cut this down just one more time.
So I think what we're likely left with is a simple description: using the explicit module path works but using the alias does not. Would you repeat the above to kill most of the 6 points so we're left with a simpler set of observations? |
I think we have all the observations and think you're right - only using an explicit path to a type annotated with @genType works. So referencing I experimented some more. I thought maybe taking out abstract types and interfaces would help but it didn't. I did find a hack! If you repeat the type in the wrapper module
|
Next, we need to know if this is about dependencies. I suspect it is not. |
Do you mean like that situation with |
Sorry I need to go to sleep. I'm not sure how to set it up. You could probably do it a lot faster than me. My repro code has the beginnings of it. |
There is no rush. The beauty of async communication. |
I created another little package and tried to add it to bs-dependencies but it didn't work because the build system was looking inside node_modules. So I put it inside node_modules and was able to use it from my main project. Same issue. If you reference a type directly like I looked back at the code that is accessing Core. When I try to use a type through the root wrapping module the TypeScript is looking for I don't want to spend more time on this. Please just take my repro repository and do whatever additional experiments you want on it. I'm very inefficient because I don't understand pinned dependencies and other things about the build system. I tried modifying |
As per my question: is there a repro without using any dependencies? |
If it exists, it's going to be a simple combination of aliasing just like for the repo. |
That repro I mentioned in this thread has trouble using gentyoe with a local file. AND there is some code that tries to use Core as a dependency. So you can see what happens in both scenarios. If you don't want the dependency just take out Core - should not have any impact on your the no-dependency case. |
Sorry if I misunderstood. It is common practice when trying to understand unexpected behaviour to cut down the possible causes. This helps coming up with solutions and debugging the issue more in detail. |
Yes I understand the need to make examples that are as simple as they can be. I think my GitHub https://github.com/jmagaram/core-gentype is very simple. Yes it has a dependency but in 1 minute you can take it out of |
Thank you. If you are confident that your example using core will have the same problem when core is removed, I will assume that dependencies can be excluded as a possible contributing factor to the issue. |
Because of this, we can close this issue, as this is the core repository. |
Ok please move the issue to the other repository and reference this one. The issue is definitely not specific to Core. |
I'll ask a "friend" to read this convo and provide a small example:
...more exchanges... I apologize for the oversight. Here's the revised example incorporating the @genType annotations: MyModule.res: @genType
type t = int
@genType
let add = (a: t, b: t): t => a + b Wrapper.res: module MyModuleAlias = MyModule
You are correct. We need an additional file that uses MyModuleAlias to fully illustrate the issue. Let's create another file called Usage.res: open Wrapper
let a = MyModuleAlias.t(5)
let b = MyModuleAlias.add(a, 3) |
I made a small alteration to the last file Usage.res: open Wrapper
let a = 5
@genType
let b = MyModuleAlias.add(a, 3) That provides the self-contained minimal repro that I will open up an issue about in the compiler repo. |
Done: rescript-lang/rescript#6112 |
GenType generates import statements for Core modules that don't work. What do I need to do to make this work?
I see in https://rescript-lang.org/docs/gentype/latest/usage#dependent-projects--libraries it says "The library must have been published with the .gen.ts files created by genType."
I've got a file
ReactFirebaseHooks.res
with this in it AND mybsconfig.json
has"bsc-flags": ["-open RescriptCore"]
This leads to the following in my
ReactFirebaseHooks.gen.tsx
...If I change the code to reference
Core__Error.gen
this is probably closer to the desired result, but still doesn't work.I tried taking out the
-open RescriptCore
but it still doesn't work. I tried addingnode_modules/~rescript/core/src
tobsconfig.json
but this shouldn't be necessary and still doesn't work.The text was updated successfully, but these errors were encountered: