-
Notifications
You must be signed in to change notification settings - Fork 441
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
RFC: New GenType for TypeScript #6196
Comments
Would you update some info which is old? As of master, gentype does not generate any runtime conversion so we can get that out of the design considerations. |
I would include removing shims as a goal. Do we need them? |
Based on this goal #6210, it seems sensible to only focus on export to JS, and move imports questions to the FFI layer, which can be revisited separately. So effectively, the concept of In particular, typed checked bindings could be re-explored in the context of #6211
|
Not sure we need a new tool. It seems easier to just add configuration to turn on the new mode. And if successful, the new mode will replace the legacy mode over time which will be deprecated and removed. |
Having GenType generate #!/usr/bin/env bash
bs_js_path="$1"
bs_ts_path="${bs_js_path/bs\.js/bs.ts}"
bs_dts_path="${bs_js_path/bs\.js/bs.d.ts}"
gen_tsx_path="${bs_js_path/bs\.js/gen.tsx}"
if [ -f "$gen_tsx_path" ]; then
mv -f "$gen_tsx_path" "$bs_ts_path"
yarn tsc --declaration --emitDeclarationOnly --isolatedModules --skipLibCheck "$(readlink -f "$gen_tsx_path")"
rm -f "$bs_ts_path"
else
rm -f "$bs_ts_path" "$bs_dts_path" "$gen_tsx_path"
fi |
This is possible if we embed |
Retreat Update: GenTypeWe (@cometkim, @JonoPrest, @cristianoc) discussed the roadmap and detailed design of the output formats in the ReScript Retreat 2024. And we have concluded most issues! If there are no remaining questions, implementation will begin as soon as possible. Core conceptsMost are similar to existing plans but are more specific. Drop attributesExcept in special cases, all Not only is this clearer, but it also significantly reduces the complexity of the compiler codebase. Drop shimsWe haven't found a legitimate use case for shims without runtimes. By supporting Also many cases may covered by using Keeping support
|
I still feel it would be useful to have |
Ok, that makes sense. IMO, just |
See #6947 (comment) |
@cometkim, if you are interested in use cases for the new design, I'm trying to use TS side export class C {
constructor(x: boolean) {};
method() { console.log(this.x) };
static staticFunction(x: number) { return [new C(true), false]; };
}
export function moduleFunction(x: number, y: boolean): string { return `${x}${y}`; }; Res side [@genType.import ("package", "C")]
type c;
// this works
[@genType.import ("package", "moduleFunction")]
external module_function_here: (int, bool) => string = "module_function_here";
// these don't work
[@genType.import] [@bs.new]
external constructor_here: bool => c = "constructor_here";
[@genType.import] [@bs.send]
external method_here: c => unit = "method_here";
[@genType.import ("package", "C.staticFunction")]
external static_here: int => (c, bool) = "static_here"; |
Proposes a new type of GenType that is incompatible with the existing GenType (will probably have the name GenType v2 or something quite different)
Motivation
GenType is a must in today's JS ecosystem starting with TypeScript. GenType is ending support for JS(untyped) and Flow, which it had previously, and is focusing more on TypeScript.
As ReScript v11 gets better interop capabilities and gets rid of runtime conversions.
It may be a good time to explore new possibilities of GenType through aggressive changes.
Goals
.d.ts
)@genType
attribute@genType.as
,@genType.import
support)Design
The key to the change is to assume the output of GenType is no longer the input of
tsc
. Instead, it becomes the direct output.The only behavior of the new GenType is to emit an interface per module. So it is not specified per binding, but per project.
Will generates
Module.bs.d.ts
next to theModule.bs.js
So makes
Module.bs.js
usable in a TypeScript project without any additional builds. That's it. All we have to do is adjust the output to represent the ReScript output.No attributes
New genType will work for all sources if enabled. It no longer requires a
@genType
attribute on a per-binding basis, nor does it introduce a per-file attribute like@@genType
.The
@genType
attribute makes PPX compatibility difficult (#6537) and requires complexity to track dependencies. This is because even if the user does not specify it, it appears implicitly according to the relationship.Configuration
Don't inherit the existing
gentypeconfig
. Almost all existing options are not required.Determine the output format and location via
package-specs
.Determine the output filename via
suffix
. e.g..bs.js
, ->.bs.d.ts
.Shims
Shims for external types are OK. Use it as-is.
If the project is a library, shims must be published together.
Nested / First-clss modules.
Namespaces might be useful for representing nested modules (See #6117). But we don't use namespaces here because it isn't compatible with type referencing and first-class module syntax.
Example: First-class modules
will generates
Opaque types
TBD
GADT
TBD
Others
Please leave comments what cases it needs to cover.
The text was updated successfully, but these errors were encountered: