Michael Van Canneyt
michael at freepascal.org
Wed Jan 5 01:58:13 CET 2022
you create an import unit for it. Pas2js ships with several such import
Making such a unit is tedious work.
Fortunately, there is now a solution.
Typescript programmers have the same problem as Pas2js programmers:
Typescript. But not all.
Luckily, there is a large library of "import libraries" for many popular
libraries (around 10.000, if my count is accurate).
How does this help us ?
This has now been extended to be able to parse Typescript.
We went a step further, and convert the TypeScript type declarations to pascal.
The result is that we can take a TypeScript declaration file
Better yet, the tool has been put in a CGI program, and is available online;
then the name will appear in the list. Selecting the correct file and
pressing "Go" will convert the file for you: a ready made pascal import
The tool is not perfect, but it will take 99% of the work out of your hands.
It parses 99.5% of all files in DefinitelyTyped.
>From the 7500 files I tested with the conversion tool, only 50 fail to convert.
More than 2000 generated files compile out-of-the box. The rest will need
yet taken into acoount, and you will most likely encounter an
'Identifier not found' error. In many cases, this can be remedied by running
the tool on the imported file, and adding the generated unit to the uses clause.
The tool is committed in the FPC repository.
It will still be improved, just as the online version, but can already be used quite well today.
More information about the Pas2js