Ideas for next version of ts2fable
See original GitHub issuePinging @jgrund @MangelMaxime @mike-morr @fsoikin. If you want to collaborate please tell me and I’ll make you collaborators of this repo 😃
These are some of the ideas I have for the next ts2fable version. Please have a look and share your feedback in the comments.
-
Convert the code to Typescript. The main reason to use TS instead of Fable is that we need to use intensively the Typescript compiler API so it makes sense to take advantage of the samples, documentation, etc already in TS, as well as the autocompletion provided by VS Code.
-
Use Typescript type checker: The current ts2fable version just does syntax parsing, the info provided from the type checker would make it easier to check inheritance, etc. It also makes it easier to translate the comments.
-
Use F# 4.1 recursive namespace: This is very easy, just add
rec
after namespace on top of the file and we don’t have to worry about writingand
for all the types. And nested modules can also reference modules below them. -
Use F# functions (
int->int->string
) instead of delegates (System.Func<int,int,string>
) for the signatures. Delegates are not needed in Fable 1.0, as F# lambdas don’t compile as nested functions any more. -
Put all the types of a TS module in an F# module suffixed with
_types
, including the generatedGlobals
type to hold module functions and values. The actual module will just become a reference to theGlobals
type, more or less as it’s now in the node bindings. -
Only use interfaces, no classes. Classes are cumbersome in the binding files because you need to fill the body with the
jsNative
placeholder. Also many features of Typescript classes cannot be represented in F# (for example, an interface in TS can inherit a class). In order to represent a class we will create two interfaces: one for the instance members and another for the static members. Then we’ll add a reference to the static interface in theGlobals
type. Example:
class Foo {
constructor();
myProperty: number;
myMethod(i: number): void;
static myStaticMethods(s: string): number;
}
type Foo =
abstract myProperty: float with get, set
abstract myMethod: float -> unit
type FooStatic =
[<Emit("new $0($1...)">]
abstract Create: unit->Foo
abstract myStaticMethods: string -> float
type Globals =
abstract Foo: FooStatic
Issue Analytics
- State:
- Created 6 years ago
- Comments:23 (19 by maintainers)
@alfonsogarciacaro Using TypeScript is a really good idea.
@alfonsogarciacaro Ok you convince me 😃