1

I'm getting started with FunScript with a working example. Using Nuget to add the needed libraries, it works well.

In watching a 2013 video on channel9, they are making use of TypeScript.Api<...> to load types from typescript definition files.

I'm however unable to find this type provider anywhere. Where is it located? I realized that a good number of the type definitions have been compiled into libraries and available on nuget but I can't really use this since some of the code will be local typescript definition files.

The questions therefore are

  1. Where is the TypeScript.Api<...> type provider?
  2. If it is not available or the best way to use typescript definition, what other options exists.
ritcoder
  • 3,274
  • 10
  • 42
  • 62

2 Answers2

2

As Thomas said, the type provider was removed mainly because it couldn't generate generic types, but the idea is to bring it back at some point.

For the moment, though not ideal, you can generate your own bindings following these steps.

  1. Download or clone Funscript repository

git clone https://github.com/ZachBray/FunScript

  1. Build the project

cd FunScript build.cmd

  1. This needs to be improved but for now you need to zip the .d.ts files you want to convert and then:

cd build\TypeScript bin\FunScript.TypeScript.exe C:\Path\to\typedefinitions.zip cd Output

Please note the first time you build the definitions it may take several minutes. Once it's done in the output folder you'll find the compiled .dll libraries with the bindings.

Also, while you're at it. It's better if you use the FunScript version you just build into build\main\bin, as it will probably be more updated than the nuget package.

Good luck and have fun(script)!

  • It worked. Now able to successfully compiled a .d.ts file. The process was however not as straight forward as one had hoped. – ritcoder Sep 07 '15 at 16:12
  • True. Unfortunately we're not improving the process because the idea is to bring the type provider back, but this may take a bit longer... – Alfonso Garcia-Caro Sep 07 '15 at 19:21
1

There were a bunch of changes in FunScript, so the TypeScript.Api<...> type provider is no longer the recommended way of calling JavaScript libraries from FunScript.

Instead, the bindings for JavaScript libraries are pre-generated and you can find them as packages on NuGet, if you search for the FunScript tag (NuGet search is not very good, so you may need to go through a number of pages to find the one you need...).

If you want to use a local TypeScript definition, then you'll need to run the command line tool to generate the bindings. The F# Atom plugin does this in the build script, so looking there is a good place to start. It has a local copy of various TypeScript bindings in the typings folder (together with the FunScript binaries needed to process them).

I liked the type provider approach much better, but sadly, type providers are somewhat restricted in what kind of types they can provide, so it wasn't all that powerful...

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • I did see some many pre-generated typescript libraries on nuget. I'm currently looking at how I can integrate F# into the usual web development process and was hoping that the type provider can make the process seamless. Will check the build script to see how it will affect the process. – ritcoder Sep 07 '15 at 13:28
  • What about type providers wasn't good enough? Looking at FunScript now and by the documentation it isn't immediately apparent that the type provider wasn't the recommended way anymore. Is it a F# limitation that might get resolved at some point? – akara Sep 24 '15 at 13:13