simn / ts2hx Goto Github PK
View Code? Open in Web Editor NEWTypescript external definitions to haxe converter
Typescript external definitions to haxe converter
This is both a ts2hx and a haxe issue:
I've generated some definition from rxjs (-d option of tsc compiler)
and I see that this library expand functionality of Observable by enhancing it's definition in file scope when someone does some imports of declaration that looks like this:
declare module "add/operator/expand" {
import { expand } from "operator/expand";
module "Observable" {
interface Observable<T> {
expand: typeof expand;
}
}
}
This one add the expand
member to Observable with the type referenced from the import.
If we want to translate that to haxe via ts2hx (with some minor tweaks to it since it was not able to parse some typescript features), then we have the problem of defining a type based on another one.
I'm refering here to the type of the expand
member which would take the type of the imported expand
thing (which is actually 3 functions).
Do you think that's something that may evolve?
I was just thinking that the Readme does not list TS libraries tested/used against, users should be encouraged to submit these with notes? By creating a list of libraries it shows feasibility and helps resolve a few objections raised against Haxe.
I was wondering if there are TS libraries currently "limited" to js target that would be worth platform generalizing, this project could maybe create stub files for more general Haxe ports or possible full transpiling. My thought is that any progress in this direction will really start to show Haxe as the better flexible solution. Imagine taking webgl TS libs and luxe-ing them, when you consider nodejs wrapper file sizes tend to be rather excessive ( node-webkit a whole browser bundled with you app, which is heavy! ), users will suddenly realize they need a Haxe solution for thier typescript project when targeting mobile.
subj
TypeScript supports callable objects with multiple signatures. We could support this with the new @:selfCall
metadata. So, we define a new method by some convention (how do we avoid potential name clashes?) adding all signatures as @:overload
and append @:selfCall
to it.
Also there are cases like this one: https://github.com/borisyankov/DefinitelyTyped/blob/1d08e36fe3ce81715cb956223f7e5a0a9882cd63/node/node.d.ts#L1341, maybe we should translate that var into an overloaded function.
https://github.com/elsassph/haxe-modular
like function Can integrate into the Haxe JS Compiler?
1 Introducing the Lib Library Not introducing Lib code
2 Compiling libraries alone does not introduce other base code
Can't build it
/usr/lib/haxe/lib/hxargs/3,0,0/hxargs/Args.hx:91: characters 43-61 : Null<haxe.macro.Expr> has no field getValue
src/tshx/Converter.hx:87: characters 64-71 : Array<{ sub : Null<String>, params : Array<haxe.macro.TypeParam>, pack : Array<String>, name : String }> should be haxe.macro.TypePath
src/tshx/Converter.hx:87: characters 64-71 : Array<{ sub : Null<String>, params : Array<haxe.macro.TypeParam>, pack : Array<String>, name : String }> should be { ?sub : Null<String>, ?params : Array<haxe.macro.TypeParam>, pack : Array<String>, name : String }
src/tshx/Converter.hx:87: characters 64-71 : Array<{ sub : Null<String>, params : Array<haxe.macro.TypeParam>, pack : Array<String>, name : String }> has no field name
src/tshx/Converter.hx:87: characters 64-71 : For function argument 'p'
Haxe 3.1, should I get nighty?
Libs from haxelib
When I do haxe build.hxml
I see run.n
get spit out, running neko run.n
then creates out
directory, but it is empty. haxe build.hxml
goes through without any stdout messages, so does neko run.n
. I was expecting to see ts2hx.n
in out
which I'd then run using neko ts2hx.n --rec…
neko
NekoVM 2.1.0 (c)2005-2016 Haxe Foundation
Usage : neko <file>
haxe -v
3.2.1
Doing neko run.n --help
gives what the README says it should. Doing neko run "input" --recur…
does seemingly nothing.
can we list which versions of typescript this typescript-to-Haxe Transpier support in README?
Attempt to use on Cats IDE written in TypeScript
https://github.com/jbaron/cats
Main.hx:93: Written out/lib/Intl.hx
Main.hx:93: Written out/lib/toplevel.hx
Called from ? line 1
Called from Main.hx line 60
Called from Main.hx line 118
Called from Main.hx line 105
Called from Main.hx line 105
Called from Main.hx line 110
Called from Main.hx line 70
Uncaught exception - local_requi:line 2:characters 10-11: NoMatch TAssign
ts2hx should generate a consistent and useful package/module structure similar to what's implemented in hxnodejs (and discussed in HaxeFoundation/hxnodejs#16 before).
basically that means the following:
for example, node's "fs" module become Fs.hx
, and "fs.Stats" goes to fs/Stats.hx
Subj.
I installed ts2hx and the current version of DefinitelyTyped. I get the following error, when running neko ts2hx.n --recursive:
Called from ? line 1
Called from Main.hx line 60
Called from Main.hx line 118
Called from Main.hx line 105
Called from Main.hx line 105
Called from Main.hx line 110
Called from Main.hx line 70
Uncaught exception - zepto-tes:line 3:characters 1-2: NoMatch TIdent($)
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#18-overloading-on-string-parameters - this could be implemented by generating a macro function that analyzes args for constant strings and types the return value apropriately.
Hi,
ts2hx doesn't work with latest hxparse.
It fails with 'src/tshx/Parser.hx:6: lines 6-437 : Class not found : hxparse.LexerTokenSource'
Any suggestions how can I ts2hx make it work?
Thanks in advance,
Dinko
see use case: https://github.com/borisyankov/DefinitelyTyped/blob/1d08e36fe3ce81715cb956223f7e5a0a9882cd63/node/node.d.ts#L1358
we should handle that properly.
I installed:
haxelib install hxparse
haxelib install hxargs
Then run haxe build.hxml
and get:
src/tshx/Parser.hx:19: lines 19-558 : Class not found : hxparse.LexerTokenSource
TypeScript apparently allows to use keywords as a variable/function name (e.g. declare var class
). We should handle haxe keywords somehow. I'm not sure whether @:native
is enough for that (e.g. @:native("class") var class_:Dynamic;
) or we should generate a property with inline getters/setters (e.g. var class_(get,set):Dynamic; inline function get_class_():Dynamic return untyped this["class"];
)
Subj. For declare module "fs" {...}
syntax we should generate @:jsRequire("fs") extern class Fs {...}
. Also we should generate proper @:jsRequire
for subtypes defined in that module.
Maybe would be better than maintaining our custom d.ts
lexer?
https://github.com/Microsoft/web-build-tools/wiki/API-Extractor
Subj. Somehow. Gotta read the spec about how does it work. 😉
I tried converting the entirety of the DefinitelyTyped repo, but many definitions failed with the following exception:
Called from ? line 1
Called from Main.hx line 69
Called from Main.hx line 111
Called from Main.hx line 87
Called from Main.hx line 101
Called from Main.hx line 92
Called from Main.hx line 154
Called from E:\Apps\Programming\HaxeToolkit\haxe\std/haxe/macro/Printer.hx line
251
Uncaught exception - Invalid field access : length
Here is one of the simplest definitions I could find:
https://github.com/borisyankov/DefinitelyTyped/blob/master/add2home/add2home.d.ts
This is nothing more than a variable declaration, containing an object with three functions.
Another example:
https://github.com/borisyankov/DefinitelyTyped/blob/master/accounting/accounting.d.ts
This defines a variable "accounting", which then gets exported in a module.
Another example:
https://github.com/borisyankov/DefinitelyTyped/blob/master/alertify/alertify.d.ts
This defines a variable, "declare var alertify: alertify.IAlertifyStatic;", and a module. The module seems to get transpiled & written correctly, but an error is also thrown, presumably because of the variable declaration. As an experiment, I removed the variable declaration line, and then no error was thrown (though I don't know if the output was entirely correct, since it would be missing the var decl conversion).
Full output log is here:
https://gist.github.com/laurence-myers/e865cae0a1c126c49337
right now, TS tuples are generated as Array<Dynamic>
which is what they actually are at runtime, but I suppose we should have a typed abstract over that to properly map typescript declaration.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.