Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Fable parser for TypeScript declaration files.
Install it with yarn or npm. With yarn it is:
yarn global add ts2fable
With npm it is:
npm install -g ts2fable
Run the ts2fable
command on a TypeScript file and also specify the F# output file. The F# namespace in taken from the output filename. In this example, it is Yargs
.
yarn add @types/yargs --dev
ts2fable node_modules/@types/yargs/index.d.ts src/Yargs.fs
You can also use --export
(or -e
) option to collect from multiple tsfiles
In below sample: All the related ts files in npm packages uifabric and office-ui-fabric-react will be compiled to OfficeReact.fs
as a bundle
ts2fable node_modules/office-ui-fabric-react/lib/index.d.ts test-compile/OfficeReact.fs -e uifabric office-ui-fabric-react
You can find more information about how to interact with JavaScript from F# here. Please note the parser is not perfect and some tweaking by hand may be needed. Please submit bugs as issues on GitHub.
You can also try out an in-browser version here
The online version will be updated automatically when commits is merged
Succesfull builds on the master branch are uploaded and tagged as next
. You can help us test these builds by installing them with:
yarn global add ts2fable@next
Windows:
git clone https://github.com/fable-compiler/ts2fable
fake.cmd run build.fsx
Unix:
git clone https://github.com/fable-compiler/ts2fable
./fake.sh run build.fsx
Common to all OS
dotnet restore dotnet-fake.proj
Ctrl+Shift+P
> Run Task > WatchTesttest/fsFileTests.fs
and prefix it with mocha only
(See below sample)Sample Test:
only "duplicated variable exports" <| fun _ ->
let tsPaths = ["node_modules/reactxp/dist/web/ReactXP.d.ts"]
let fsPath = "test-compile/ReactXP.fs"
testFsFiles tsPaths fsPath <| fun fsFiles ->
fsFiles
|> getTopVarialbles
|> List.countBy(fun vb -> vb.Name)
|> List.forall(fun (_,l) -> l = 1)
|> equal true
As above, clone then run fake.cmd run build.fsx
.
Now compile the local sources:
cd ./tools
dotnet fable yarn-fable-splitter -- ./src/ts2fable.fsproj --config ./tools/splitter.config.js --port free
This should have created a folder ./dist
.
You can now execute it through node: node ./dist/ts2fable.js C:\projects\MyCoolProject\node_modules\babylonjs\babylon.d.ts C:\projects\MyCoolProject\Bindings\BabylonJS\babylonjs.fs
Some JavaScript/TypeScript features have no direct translation to F#. Here is a list of common workarounds adopted by the parser to solve these problems:
type CanvasRenderingContext2D =
abstract fillStyle: U3<string, CanvasGradient, CanvasPattern> with get, set
let ctx: CanvasRenderingContext2D = failwith "dummy"
ctx.fillStyle <- U3.Case1 "#FF0000"
new
keyword. In the parsed files, interfaces with this
capability will have a Create
method attached:type CanvasRenderingContext2DType =
abstract prototype: CanvasRenderingContext2D with get, set
[<Emit("new $0($1...)")>] abstract Create: unit -> CanvasRenderingContext2D
Invoke
method to callable interfaces:type Express =
inherit Application
abstract version: string with get, set
abstract application: obj with get, set
[<Emit("$0($1...)")>] abstract Invoke: unit -> Application
FAQs
TypeScript definition files parser for fable-compiler
The npm package ts2fable receives a total of 214 weekly downloads. As such, ts2fable popularity was classified as not popular.
We found that ts2fable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.