-
Notifications
You must be signed in to change notification settings - Fork 453
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
@genType not generating correct TypeScript definitions for module aliases #6112
Comments
This might be related...
|
Amazing. I want to try this. What version is this in? Not sure how to get it using my |
@jmagaram You can go to any successful GitHub action run like this one: https://github.com/rescript-lang/rescript-compiler/actions/runs/4649563108 and download the npm-packages artifact. e.g. |
This seems to work pretty well EXCEPT for the last case below which may or may not be related to this. I'll open a separate issue. EXPERIMENT 1In my repro example I added @genType to the module in the
...and then when I try to use
One thing that is interesting and useful is that when I apply @genType to the module alias it exports EVERYTHING in the module to TypeScript, not just those items in the module that have annotations on them. I think this is very intuitive. I'm saying "generate typescript for this whole module" and that is what it is doing. EXPERIMENT 2When I put the annotation on the result of the functor it takes everything in that module and exports it.
EXPERIMENT 3It works just for regular modules like this...
EXPERIMENT 4I tried to see what happens if there are annotation inside the module. This exports everything in the module and does the special renaming on the type t.
EXPERIMENT 5I'm looking at @genType.ignoreInterface and external functions.
|
Experiment 6This doesn't work. Nothing gets generated. If I put
|
Description:
When using @genType with module aliases, the generated TypeScript definitions are not correctly referencing the aliased modules. This issue occurs when trying to access types and functions through the module alias.
Example:
Consider the following ReScript code:
// MyModule.res
@genType
type t = int
@genType
let add: (t, int) => int = (x, y) => x + y
// Wrapper.res
module MyModuleAlias = MyModule
// Usage.res
open Wrapper
let a = 5
@genType
let b = MyModuleAlias.add(a, 3)
Expected behavior:
The @genType annotations should generate the correct TypeScript type definitions and import paths, even when using module aliases.
Actual behavior:
The generated TypeScript definitions are not correctly referencing the aliased modules, causing issues when trying to use the aliased types and functions in a TypeScript/JavaScript context.
For more discussion see: rescript-lang/rescript-core#128
The text was updated successfully, but these errors were encountered: