question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ideas for next version of ts2fable

See original GitHub issue

Pinging @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 writing and 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 generated Globals type to hold module functions and values. The actual module will just become a reference to the Globals 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 the Globals 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:closed
  • Created 6 years ago
  • Comments:23 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
MangelMaximecommented, Mar 28, 2017

@alfonsogarciacaro Using TypeScript is a really good idea.

1reaction
MangelMaximecommented, Apr 3, 2017

@alfonsogarciacaro Ok you convince me 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I get started on a Fable2TS plugin? : r/fsharp
What I think might be a better approach is to take the idea from elm, specifically elm ports, and write a plugin /...
Read more >
Three.js + F# + Fable = ❤. Making the 3D ...
Looking at the JavaScript code of the sample, use the ts2fable output file as a reference and find only the types I need...
Read more >
ts2fable
ts2fable npm version. Fable parser for TypeScript declaration files. Usage. Install it with yarn or npm. With yarn it is:
Read more >
Does F# have a future? - General
If you look at programming in general, functional programming is still a niche approach. Most programming still seems to be C, C++, JavaScript, ......
Read more >
Dependency Trees With Fable and Sutil - queil.net
I've quickly realised that to use an external library I need Fable bindings for it. So there is the ts2fable tool one can...
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found