Fable
Fable copied to clipboard
[TypeScript] 4.0.0-theta-001 generates ts code with errors
Description
The generated typescript code seems to be broken in latest alpha/theta version. I also checked with earlier versions, so maybe I am expecting something here that does not actually work? Im trying to compile some fsharp code that uses Fable.Remoting to typescript.
Repro code
git clone --branch add-broken-fable4-remoting-sample https://github.com/guilherme-aarao-rodrigues/fsharp-experiments
cd fsharp-experiments\fable-remoting
dotnet restore
dotnet fable .\ClientLib.fsproj --typedArrays false --lang typescript
Expected and actual results
Expected: The generated code should not have typescript errors
Actual:
In the generated code there are many import typescript errors, i.e.
and also inline errors:
Related information
- Fable version: 4.0.0-theta-001
- Operating system: windows
- client code: sample call to Fable.Remoting
Sorry this is not very clear at the moment @jannikbuschke, but Typescript compilation is not in a working state yet. It was added experimentally a while ago but we haven't worked more on it. We want to make it work during the Fable 4 cycle but it will still take some time.
@alfonsogarciacaro can you point me in the direction where the current ts compilation is implemented?
It's actually the same as the JS compilation, the only difference is there are several switches in the Fable2Babel step so when Typescript is selected type annotations are included in the generated AST. Example: https://github.com/fable-compiler/Fable/blob/27e801ff9bc7f5bc9c2d72b404b827cbae69dc34/src/Fable.Transforms/Fable2Babel.fs#L542-L554
This work was done by @ncave. I think most of it works fine, but we need to have another CI job to run the tests in TypeScript to make sure everything is working. IIRC one of the problems is the generated TS code still references the fable-library distributed in JS form and this makes the TypeScript type checker complain. We need to distribute fable-library also in TS form (as we do now with Python, Rust, Dart).
Will the story for ts/js be to let Fable generate ts code and let some transpiler (babel/tsc) generate the js output? Seems to be a clean solution in the long run, but maybe not easily achievable? I hope I will find some time to help in ts support, actually would love to start using Fable, awesome work
TypeScript support hasn't been touched in a while, so it's still in alpha and needs some love.
First step would be to make the fable-library-ts
compile (i.e. npm run build library-ts
).
Next step would be to make tests compile on TypeScript, but that's a much bigger task.
Contributors and ideas are always welcome, no contribution is too small.
@jannikbuschke
Will the story for ts/js be to let Fable generate ts code
Yes, that's how it should work for all supported languages. Fable is just a transpiler from F# to some target language.
TypeScript support has been officially included in Fable.
I am closing this issue as it should in theory not happen now. If this is still the case, please feel free to re-open or create a new issue