kotlin / dukat Goto Github PK
View Code? Open in Web Editor NEWConverter of <any kind of declarations> to Kotlin external declarations
Converter of <any kind of declarations> to Kotlin external declarations
While translating moment.js
all functions-constructors are defined without @JsModule('moment')
, so moment is not automatically loaded in JS code.
Possible solutions:
-m
for specifying the name of modulenode_modules
directly and work with the directory or receive directory as an argumentHi, I'm trying to translate knex/knex.d.ts
into .kt
file.
And, I got the following error now.
Unsupported node.kind: 230, name: ImportDeclaration (testDefinitelyTyped/DefinitelyTyped/knex/knex.d.ts:9:38 to 10:34)
What I understood is that ts2kt does not support some subset of syntax yet, at least one in the knex.d.ts
.
I'd like to know what that unsupported syntax exactly is, and how can I contribute to support it.
Here is a code snippet from knex.d.ts
, where the error got thrown.
// knex.d.ts:9:38 to 10:34
import Promise = require("bluebird");
import * as events from "events";
Converting jQuery doesn't yield any direct errors, but I was expecting to be able to write
jQuery("#foo")
as a result. However, this is invalid, as all of the four overloads match equally well:
@nativeInvoke
operator fun invoke(selector: String, context: Element? = definedExternally /* null */): JQuery
@nativeInvoke
operator fun invoke(selector: String, context: JQuery? = definedExternally /* null */): JQuery
@nativeInvoke
operator fun invoke(`object`: Any): JQuery
@nativeInvoke
operator fun invoke(html: String, ownerDocument: Document? = definedExternally /* null */): JQuery
/home/max/IdeaProjects/kiq
├── @types/[email protected]
└─┬ [email protected]
└── [email protected]
Kotlin has an import as
structure but the utility doesn't include imports to .kt
files.
export declare class SomeClass {
static foo<T extends SomeClass>(this: OtherClass<T>, entity: T): any;
}
produce:
external open class SomeClass {
companion object {
fun <T : SomeClass> foo(this: OtherClass<T>, entity: T): Any = definedExternally
} // ^
} // Error: Parameter name expected
It could be thisRef:
, for example
I used ts2kt on webix definitions (using typings : "webix": "registry:dt/webix#4.2.0+20170223145009"
)
It runs smoothly ```
$ ts2kt front/typings/globals/webix/index.d.ts
Converting front/typings/globals/webix/index.d.ts
Save declarations:
./index.kt
./index.webix.kt
./index.webix.ui.kt
./index.webix.ui.datafilter.kt
But the generated file don't compile under kotlin-1.1.1
Sample of generated code ```
external interface AtomDataLoader {
fun load(url: String, type: String? = definedExternally /* null */, callback: (args: Any) -> Any? = definedExternally /* null */): webix.promise
fun parse(data: Any, type: String)
companion object : AtomDataLoader by definedExternally: AtomDataLoader {
}
}
The compilation fail with the following title : Can't use delegate on external declaration
(There is also some other issues with this typings definition (missing import and definition))
ts2kt version :
0.0.20
material-ui version:
@types/[email protected]
ts2kt conversion results in weird interfaces names :
external interface `T$43` {
@nativeInvoke
operator fun invoke(locales: Array<String>? = definedExternally /* null */, options: Intl.DateTimeFormatOptions? = definedExternally /* null */): Intl.DateTimeFormat
@nativeInvoke
operator fun invoke(locale: String? = definedExternally /* null */, options: Intl.DateTimeFormatOptions? = definedExternally /* null */): Intl.DateTimeFormat
fun supportedLocalesOf(locales: Array<String>, options: Intl.DateTimeFormatOptions? = definedExternally /* null */): Array<String>
fun supportedLocalesOf(locale: String, options: Intl.DateTimeFormatOptions? = definedExternally /* null */): Array<String>
@nativeInvoke
operator fun invoke(): Intl.DateTimeFormat
}
Example:
interface Foo {
}
declare module "mymodule" {
function foo(): Foo;
}
results in:
package overloadedFunctions
external interface Foo
and
@file:JsModule("mymodule")
package overloadedFunctions.mymodule
external fun foo(): Foo = definedExternally
but it should be:
package overloadedFunctions
external interface Foo
and
@file:JsModule("mymodule")
package overloadedFunctions.mymodule
external fun foo(): overloadedFunctions.Foo = definedExternally
OR it should be (without creating a kotlin package for a module):
package overloadedFunctions
external interface Foo
@JsModule("mymodule")
external fun foo(): Foo = definedExternally
Relates to: Kotlin/ts2kt#50
16.10
1.1RC
0.21.3
0.0.8
2.2.1
The output generated by ts2kt seems to not be usable. It's missing imports, and the IDE complains also about missing external
keyword.
Also it adds an extra dot like output..kt
.
In a npm/yarn project:
npm install ts2kt --save-dev
or yarn add ts2kt --dev
npm install vue
or yarn add vue
package.json
, add {"scripts":"ts2kt": "ts2kt"}
mkdir ./output/path
(otherwise, it seems to not work)npm run ts2kt -- -d ./output/path ./node_modules/vue/types/vue.d.ts
or yarn run ts2kt -- -d ./output/path ./node_modules/vue/types/vue.d.ts
For me, I get:
Terminal output:
tristancaron@XPS:~/IdeaProjects/myProject$ yarn run ts2kt -- -d ./src/lib/vue ./node_modules/vue/types/vue.d.ts
yarn run v0.21.3
$ "/home/tristancaron/IdeaProjects/myProject/node_modules/.bin/ts2kt" -d ./src/lib/vue ./node_modules/vue/types/vue.d.ts
Converting ./node_modules/vue/types/vue.d.ts
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:1:1 to 10:20)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:10:20 to 11:71)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:11:71 to 12:57)
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:50:8 to 50:23)
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:51:11 to 51:29)
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:81:78 to 81:89)
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:81:78 to 81:89)
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:93:73 to 93:84)
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:93:73 to 93:84)
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:96:22 to 96:33)
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/vue/types/vue.d.ts:98:26 to 98:62)
Save declarations:
./src/lib/vue/vue..kt
Done in 0.60s.
You can get the type definitions from https://github.com/kelseasy/web-ext-types
These files should be split into multiple files in order to compile.
The .out file could be kept as a single file which is compared with multiple.
There are such large projects, written directly in TypeScript and contains complex directory structure with a lot of files (hundreds). Such projects are compiled with option --declaration
(which autogenerate *.d.ts
for each *.ts
files) and published directly to npm
Trying to convert typings of such project, I ran into a number of problems. Here are some of them:
dukat
will take *.d.ts
files recursively and put result to destination directory keeping source directory structure. It could be resolved with some scripting, but...*.d.ts
files via $ dukat /path/to/**/*.d.ts
. It takes > 1 hour
to convert them (2-4 files per minute)-b some_package_name
gave no effect. Each file get same package name as it file name. It also don't work for single file. I expect that I can specify same package name for all files. Ability to specify @file:JsModule("path-to-module")
would be also useful.'T$0'
will be duplicated, because each file converted independently.external class
implement interface from another file, there are no override
modifier, because each file converted independently.package.json
could contain types
property or index.d.ts
at the root of the package. It would be nice if also it were ability to analyze dependencies starting from index.d.ts
before just converting all files from npm package.index.d.ts
contains re-exports.This was an issue when converting firebase-app.d.ts
Example:
declare class VarTypeOfClass {
myVar: typeof someOtherVar;
}
Should be this at a minimum:
external open class VarTypeOfClass {
open var myVar: dynamic /* typeof someOtherVar */ = definedExternally
}
But ideally it would determine the actual type of myVar and specify it directly.
Some libraries, in this case js-joda
, declare their equals methods as taking (TypeScript) any
. This results in the Kotlin stub function override fun equals(other: Any): Boolean
, however this doesn't actually override Any#equals
which is defined as nullable: fun equals(other: Any?): Boolean
. I think the correct behavior here would be to emit other: Any?
in the stub, since TypeScript's any
type may be null/undefined as well.
If the source declaration file has comments, could we have an option to keep them when converting to Kotlin?
For example, see alertify.d.kt#L29
Converting node_modules/@types/three/index.d.ts
ts2kt: "ExportDeclaration" kind unsupported yet here! (node_modules/@types/three/index.d.ts:1:1 to 6:30)
ts2kt: "ExportDeclaration" kind unsupported yet here! (node_modules/@types/three/index.d.ts:6:30 to 8:40)
ts2kt: "ExportDeclaration" kind unsupported yet here! (node_modules/@types/three/index.d.ts:8:40 to 9:39)
...
Specific code it's complaining about is code like this: export * from "./three-core";
And likely also: export as namespace THREE;
Example:
export type GeographicScope = 'city' | 'state' | 'country' | 'world';
export interface MapGenerator {
generate(scope: GeographicScope)
}
Is resulting in:
external interface MapGenerator {
fun generate(scope: String /* "city" */)
fun generate(scope: String /* "state" */)
fun generate(scope: String /* "country" */)
fun generate(scope: String /* "world" */)
}
but should be:
external interface MapGenerator {
fun generate(scope: String /* "city" | "state" | "country" | "world" */)
}
NullPointerException: null
at Object.throwNPE (C:\Users\scott_huang\AppData\Roaming\npm\node_modules\ts2kt\kotlin.js:3325:11)
at TsClassToKt.visitClassDeclaration_4wvyue$ (C:\Users\scott_huang\AppData\Roaming\npm\node_modules\ts2kt\ts2kt.js:1956:114)
at TypeScriptToKotlin.visitClassDeclaration_4wvyue$ (C:\Users\scott_huang\AppData\Roaming\npm\node_modules\ts2kt\ts2kt.js:2494:16)
at visitNode (C:\Users\scott_huang\AppData\Roaming\npm\node_modules\ts2kt\ts2kt.js:1864:15)
at C:\Users\scott_huang\AppData\Roaming\npm\node_modules\ts2kt\ts2kt.js:1840:7
at visitEachNode (C:\Users\scott_huang\AppData\Roaming\npm\node_modules\ts2kt\node_modules_typescript@2.0.10@typescript\lib\typescript.js:8343:30)
at forEachChild (C:\Users\scott_huang\AppData\Roaming\npm\node_modules\ts2kt\node_modules_typescript@2.0.10@typescript\lib\typescript.js:8503:24)
at forEachChild_0 (C:\Users\scott_huang\AppData\Roaming\npm\node_modules\ts2kt\ts2kt.js:1844:5)
at TypeScriptToKotlinBase.visitList_uvf806$ (C:\Users\scott_huang\AppData\Roaming\npm\node_modules\ts2kt\ts2kt.js:2846:5)
at TypeScriptToKotlin.visitList_uvf806$ (C:\Users\scott_huang\AppData\Roaming\npm\node_modules\ts2kt\ts2kt.js:2720:56)
Example:
declare function foo(s: "number"): number;
declare function foo(s: "string"): string;
results in:
external fun foo(s: String /* "number" */): Number = definedExternally
external fun foo(s: String /* "string" */): String = definedExternally
but it should be:
external fun foo(s: String /* "number" | "string" */): dynamic = definedExternally
Found out while converting firebase typings with ts2kt
that types declared with: export declare type
were not converted and missing from .kt
at all.
Trying to convert Underscore generates a number of errors, though possibly not too many to correct by hand.
Initial conversion warnings:
Converting node_modules/@types/underscore/index.d.ts
ts2kt: "NamespaceExportDeclaration" kind unsupported yet here! (node_modules/@types/underscore/index.d.ts:7:12 to 8:23)
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/@types/underscore/index.d.ts:184:17 to 184:30)
Save declarations:
headers/index.kt
headers/index._.kt
Other things:
At the top of the file,
@file:[JsQualifier("_"), JsModule("_")]
I get the "No commas needed to separate annotations" error.
fun <T> map(list: _.List<T>, iterator: _.IterateePropertyShorthand, context: Any? = definedExternally /* null */): Array<T>
fun <T> map(list: _.List<T>, iterator: _.IterateeMatcherShorthand<Any>, context: Any? = definedExternally /* null */): Array<Boolean>
IterateePropertyShorthand
and IterateeMatcherShorthand
are both undefined.
fun tap(interceptor: (as: Any) -> Any): Any
as
is a reserved word, but not handled.
fun <T, U> mapObject(`object`: _.Dictionary<T>, iteratee: (val: T, key: String, object: _.Dictionary<T>) -> U, context: Any? = definedExternally /* null */): _.Dictionary<U>
fun <T> mapObject(`object`: Any, iteratee: (val: Any, key: String, object: Any) -> T, context: Any? = definedExternally /* null */): _.Dictionary<T>
val
and object
are not handled when they appear as block arguments.
These are just the unique errors -- these same errors come up a number of times in the generated file.
Warnings:
@nativeInvoke
, @nativeGetter
, @nativeSetter
"unused", "AddVarianceModifier"
were added to the list of warnings to suppress at the file level.directory
├── @types/[email protected]
├── @types/[email protected]
└─┬ [email protected]
└── [email protected]
Example:
type Ref<T> = string | ((instance: T) => any);
declare function addRef(ref: Ref<number>);
results in compilation error:
external fun addRef(ref: String): Unit = definedExternally
external fun addRef(ref: (instance: T) -> Any): Unit = definedExternally
but it should be:
external fun addRef(ref: String): Unit = definedExternally
external fun addRef(ref: (instance: Number) -> Any): Unit = definedExternally
I think it is the hugest obstacle for global .d.ts
to .kt
translation.
For example, I installed express
and 50 packages got downloaded, jest
- more than 500! Not every of them has definition files but some do. Manual fixing is not an option.
ts2kt
is already able to put all the files in the specified directory. It would be nice if the utility compared files, present in output directory with the whole node_modules
. I see it this way:
-s[can] <dir>
) or, if not specified, use app-root-path to define root of project based on pwd
.package.json
and look through all @types/*
dependencies and compare it to -d <dir>
.-f
) and all the packages will be translated without any comparison.package.json
and look through all other dependencies that have property types
in their module's package.json
set. Queue all of them and repeat actions 2.1 - 2.3../lib
or ./declarations
in our project.Another advantage is fast way of creating and filling js-externals
repo and this created ability to make a TS-like ecosystem inside of node_modules/@kotlin
or @ktypes
or @kt
or whatever :)
$ npm i dukat -g
$ dukat some.d.ts
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jetbrains/dukat/nashorn/DocumentCache has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.jetbrains.dukat.compiler.TranslatorGraal.<init>(translator.kt:142)
at org.jetbrains.dukat.compiler.TranslatorKt.createGraalTranslator(translator.kt:153)
at org.jetbrains.dukat.cli.CliKt.main(cli.kt:172)
$ java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
macOS 10.13.6
Hi all,
I started using "create-react-kotlin-app," thus Kotlin with React and NodeJS and wanted to get all NodeJS types for code assistance and ease of import within my Kotlin project.
However, converting the index.d.ts inside the @types/node folder results in many errors and the final web application quits due to compilation errors.
Maybe you can guide me what I am doing wrong?
Using ts2kt on macOS 10.13.4 with IntelliJ IDEA Ultimate 2018.1, and node 9.11.1 / npm 5.6.0
Following you'll find the output from ts2kt and after this a txt file containing the output from the web server:
ts2kt version: 0.1.3
Converting node_modules/@types/node/index.d.ts
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:138:27 to 139:10)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:139:53 to 140:12)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:140:55 to 141:12)
ts2kt: "TypeQuery" kind unsupported yet here! (node_modules/@types/node/index.d.ts:789:19 to 789:36)
ts2kt: "ExportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:889:41 to 890:63)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:940:24 to 941:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:941:38 to 942:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:942:32 to 943:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:943:38 to 944:31)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:947:43 to 948:17)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:948:27 to 949:38)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:949:48 to 950:43)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:950:53 to 951:40)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:951:50 to 952:33)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:952:43 to 953:39)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:953:49 to 954:39)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:954:49 to 955:23)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:955:33 to 956:24)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:956:34 to 957:24)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:957:34 to 958:14)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:958:24 to 959:16)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:959:26 to 960:18)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:960:28 to 961:24)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:961:34 to 962:21)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:962:31 to 963:30)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:963:40 to 964:27)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:964:37 to 965:27)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:965:37 to 966:25)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:966:35 to 967:27)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:967:37 to 968:24)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:968:34 to 969:23)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:969:33 to 970:15)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:970:25 to 971:18)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:971:28 to 972:15)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:972:25 to 973:24)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:973:34 to 974:19)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:974:29 to 975:17)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:975:27 to 976:29)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:976:39 to 977:26)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:977:36 to 978:22)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:978:32 to 979:21)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:979:33 to 980:36)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:980:46 to 981:18)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:981:28 to 982:28)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:982:38 to 983:13)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:983:23 to 984:18)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:984:28 to 985:15)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:985:25 to 986:14)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:986:24 to 987:18)
ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/node/index.d.ts:987:28 to 988:27)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1180:27 to 1181:44)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1181:44 to 1182:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1182:38 to 1183:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1438:24 to 1439:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1746:25 to 1747:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1747:32 to 1748:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1748:38 to 1749:34)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1749:34 to 1750:31)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1795:24 to 1796:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1796:38 to 1797:42)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1862:28 to 1863:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:1863:38 to 1864:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2005:33 to 2006:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2006:38 to 2007:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2007:38 to 2008:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2315:23 to 2316:50)
ts2kt: "ComputedPropertyName" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2383:44 to 2384:26)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2572:23 to 2573:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2573:38 to 2574:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2574:38 to 2575:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2817:25 to 2818:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2818:38 to 2819:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2920:22 to 2921:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2921:38 to 2922:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:2922:38 to 2923:31)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:4741:23 to 4742:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:4742:38 to 4743:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:4743:32 to 4744:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:4744:32 to 4745:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:5285:26 to 5286:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:5641:23 to 5642:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:5657:26 to 5658:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:6158:25 to 6159:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:6159:38 to 6160:30)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:6160:30 to 6161:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:6161:32 to 6162:38)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:6162:38 to 6163:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:6163:32 to 6164:32)
ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:6164:32 to 6166:69)
ts2kt: "ExportDeclaration" kind unsupported yet here! (node_modules/@types/node/index.d.ts:6166:69 to 6167:69)
Save declarations:
src/types/index.kt
src/types/index.setTimeout.kt
src/types/index.setImmediate.kt
src/types/index.NodeJS.kt
src/types/index.buffer.kt
src/types/index.querystring.kt
src/types/index.events.kt
src/types/index.http.kt
src/types/index.cluster.kt
src/types/index.zlib.kt
src/types/index.zlib.constants.kt
src/types/index.os.kt
src/types/index.https.kt
src/types/index.punycode.kt
src/types/index.repl.kt
src/types/index.readline.kt
src/types/index.vm.kt
src/types/index.child_process.kt
src/types/index.child_process.exec.kt
src/types/index.child_process.execFile.kt
src/types/index.url.kt
src/types/index.dns.kt
src/types/index.dns.lookup.kt
src/types/index.dns.resolve.kt
src/types/index.dns.resolve4.kt
src/types/index.dns.resolve6.kt
src/types/index.net.kt
src/types/index.dgram.kt
src/types/index.fs.kt
src/types/index.fs.rename.kt
src/types/index.fs.truncate.kt
src/types/index.fs.ftruncate.kt
src/types/index.fs.chown.kt
src/types/index.fs.fchown.kt
src/types/index.fs.lchown.kt
src/types/index.fs.chmod.kt
src/types/index.fs.fchmod.kt
src/types/index.fs.lchmod.kt
src/types/index.fs.stat.kt
src/types/index.fs.fstat.kt
src/types/index.fs.lstat.kt
src/types/index.fs.link.kt
src/types/index.fs.symlink.kt
src/types/index.fs.readlink.kt
src/types/index.fs.realpath.kt
src/types/index.fs.realpathSync.kt
src/types/index.fs.unlink.kt
src/types/index.fs.rmdir.kt
src/types/index.fs.mkdir.kt
src/types/index.fs.mkdtemp.kt
src/types/index.fs.readdir.kt
src/types/index.fs.close.kt
src/types/index.fs.open.kt
src/types/index.fs.utimes.kt
src/types/index.fs.futimes.kt
src/types/index.fs.fsync.kt
src/types/index.fs.write.kt
src/types/index.fs.read.kt
src/types/index.fs.readFile.kt
src/types/index.fs.writeFile.kt
src/types/index.fs.appendFile.kt
src/types/index.fs.exists.kt
src/types/index.fs.constants.kt
src/types/index.fs.access.kt
src/types/index.fs.fdatasync.kt
src/types/index.fs.copyFile.kt
src/types/index.path.kt
src/types/index.path.posix.kt
src/types/index.path.win32.kt
src/types/index.string_decoder.kt
src/types/index.tls.kt
src/types/index.crypto.kt
src/types/index.stream.kt
src/types/index.util.kt
src/types/index.util.promisify.kt
src/types/index.assert.kt
src/types/index.assert.internal.kt
src/types/index.tty.kt
src/types/index.domain.kt
src/types/index.constants.kt
src/types/index.v8.kt
src/types/index.timers.kt
src/types/index.timers.setTimeout.kt
src/types/index.timers.setImmediate.kt
src/types/index.async_hooks.kt
src/types/index.http2.kt
src/types/index.http2.constants.kt
src/types/index.perf_hooks.kt
src/types/index.perf_hooks.constants.kt
export abstract class A {
abstract close(): void
}
converts to:
external open class A {
open fun close(): Unit = definedExternally
}
The class and function are missing the abstract modifier
It would be really awesome if we could have a [at]types like npm repo, but for koltin. Meaning that whenever the [at]types repo is updated, a similar update goes output for the kotlin types repo. This would make it many times easier to maintain types, without having to manually convert with the typescript types.
I just installed latest version and saw that ts2kt
still does not handle partials. One could ignore TypeScript, but the situation when a lot of fields in the JS object are optional is fairly frequent. I want to propose one of the possible ways to handle it without modifying something in the language itself.
Consider generated interface
external interface Point {
var x: Number
var y: Number
var z: Number
}
I propose to check the whole definition to see if this class is used as Partial
somewhere, generate something like that instead:
fun Point(builder: Point.()->Unit): Point{
return object : Point{
override var x: Number? = null
override var y: Number? = null
override var z: Number? = null
}.apply(builder)
}
external interface Point: Partial {
var x: Number?
var y: Number?
var z: Number?
}
Partial
here is a marker interface for future reference.
Then object construction will look like this:
val myPoint = Point{ x = 1, y = 2}
The drawback is that one enforces nullability on all fields, but obviously if partial is used anywhere, it is indeed nullable.
When I tried to use ts2kt to convert babylon.js's type definition file to .kt files, I got log like below and the converted babylon.*.kt files got hundreds of compile errors.
The babylon.d.ts can be found from https://github.com/BabylonJS/Babylon.js/tree/master/dist.
ts2kt version: 0.0.14
Converting babylon.d.ts
ts2kt: "TypeQuery" kind unsupported yet here! (babylon.d.ts:170:30 to 170:46)
ts2kt: "SymbolKeyword" kind unsupported yet here! (babylon.d.ts:14068:81 to 14068:88)
ts2kt: "SymbolKeyword" kind unsupported yet here! (babylon.d.ts:14069:90 to 14069:97)
ts2kt: "SymbolKeyword" kind unsupported yet here! (babylon.d.ts:14070:89 to 14070:96)
ts2kt: "SymbolKeyword" kind unsupported yet here! (babylon.d.ts:14071:100 to 14071:107)
ts2kt: "SymbolKeyword" kind unsupported yet here! (babylon.d.ts:14072:90 to 14072:97)
ts2kt: "SymbolKeyword" kind unsupported yet here! (babylon.d.ts:14073:90 to 14073:97)
ts2kt: "SymbolKeyword" kind unsupported yet here! (babylon.d.ts:14074:96 to 14074:103)
ts2kt: "SymbolKeyword" kind unsupported yet here! (babylon.d.ts:14075:94 to 14075:101)
ts2kt: "SymbolKeyword" kind unsupported yet here! (babylon.d.ts:14076:89 to 14076:96)
ts2kt: "SymbolKeyword" kind unsupported yet here! (babylon.d.ts:14077:111 to 14077:118)
ts2kt: Merging Variable and ??? unsupported yet, a: var Window.VRFrameData: Any get() = definedExternally; set(value) = definedExternally
, b: var VRFrameData: Any = definedExternally
ts2kt: Merging Variable and ??? unsupported yet, a: var WebGLTexture.references: Number get() = definedExternally; set(value) = definedExternally
, b: var WebGLBuffer.references: Number get() = definedExternally; set(value) = definedExternally
Save declarations:
./babylon.kt
./babylon.BABYLON.kt
./babylon.SIMD.kt
./babylon.BABYLON.Debug.kt
./babylon.BABYLON.Geometry.Primitives.kt
./babylon.BABYLON.Internals.kt
./babylon.Earcut.kt
Example:
interface Foo {
baz: any
}
interface Boo extends Foo {
baz: number
}
results in
external interface Foo {
var baz: Any
}
external interface Boo : Foo {
override var baz: Number
}
which fails with compilation error:
"Type of 'baz' doesn't match the type of the overridden var-property 'public abstract var baz: Any defined in interface
.override.Foo'."
One solution is to make it be (see https://stackoverflow.com/questions/44740473/kotlin-type-of-exoplayer-doesnt-match-the-type-of-the-overridden-var-propert/44741377#44741377):
external interface Foo {
val baz: Any
}
external interface Boo : Foo {
override var baz: Number
}
Another is to make it be:
external interface Foo {
var baz: dynamic
}
external interface Boo : Foo {
override var baz: Number
}
Yet another is to make it be:
external interface Foo<T> {
var baz: T
}
external interface Boo : Foo<Number> {
override var baz: Number
}
Still another is to make it be:
external interface Foo {
var baz: Any
}
external interface Boo : Foo {
override var baz: Any /* Number */
}
Trying to convert the Node.js bindings which uses the /// <reference path="globals.d.ts" />
syntax for including other files. It seems that ts2kt tries to look for references relative to the filesystem root, as per this stacktrace:
types/node (master) ➥ ts2kt -d kotlin index.d.ts
ts2kt version: 0.1.3
Converting index.d.ts
fs.js:119
throw err;
^
Error: ENOENT: no such file or directory, open '/base.d.ts'
at Object.openSync (fs.js:448:3)
at Object.readFileSync (fs.js:348:35)
at getScriptSnapshotFromFile (/usr/lib/node_modules/ts2kt/ts2kt.js:5398:46)
at translate (/usr/lib/node_modules/ts2kt/ts2kt.js:5623:21)
at translateToDir (/usr/lib/node_modules/ts2kt/ts2kt.js:5177:26)
at main (/usr/lib/node_modules/ts2kt/ts2kt.js:5387:5)
at /usr/lib/node_modules/ts2kt/ts2kt.js:6243:3
at Object.<anonymous> (/usr/lib/node_modules/ts2kt/ts2kt.js:6246:2)
at Module._compile (internal/modules/cjs/loader.js:738:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
The reference paths don't have the preceding slash so something in ts2kt seems to be adding it.
Hello!
I'm trying to process bunch of .ts files, particularly firebase
declarations from this repo:
https://github.com/firebase/firebase-js-sdk
I've prepared simple script:
class Converter {
fun convertAll(path: String) = runBlocking {
val root = File(path)
println("root=${root.absolutePath}")
File("converted").mkdirs()
root.walk()
.filter { file -> file.isFile && file.name.endsWith(".d.ts") }
.asIterable()
.map { file ->
val dest = file.parent.replace("^\\w+[/\\\\]".toRegex(), { "converted${File.separator}" })
println("$file -> $dest")
val command = "cmd.exe /c ts2kt -d $dest $file"
doJob(command)
}
.forEach {
it.join()
}
}
private fun doJob(command: String) = launch {
println(command)
val process = Runtime.getRuntime().exec(command)
process.waitFor()
}
}
it works ok, but i see lot of clashed redeclarations in generated code like
external interface
T$0``
external interface
T$1``
etc
It would be nice to have batch mode in ts2kt tool that will allow to generate unique names per files pack. Someting like ts2kt -f <folder>
they end up with package statements that don't match they file location
ts2kt version: 0.1.3
A fragment from phaser.d.ts (https://github.com/photonstorm/phaser3-docs/blob/master/typescript/phaser.d.ts):
declare type GameConfig = {
input?: boolean | object;
"input.keyboard"?: boolean;
...
}
results into ts2kt: "StringLiteral" kind unsupported yet here!
in the stderr.
export class A {
protected close(): void
}
converts to:
external open class A {
open fun close(): Unit = definedExternally
}
The function is missing the protected modifier
Example:
File: objectType/asTypeAliasInNamespaces/asTypeAliasInNamespaces.d.ts
declare namespace a {
type I = {
foo(): string
}
}
declare namespace b {
function bar(): a.I
}
results in:
File: objectType/asTypeAliasInNamespaces/a/asTypeAliasInNamespaces.a.d.kt
@file:JsQualifier("a")
package objectType.asTypeAliasInNamespaces.a
external interface I {
fun foo(): String
}
and
File: objectType/asTypeAliasInNamespaces/b/asTypeAliasInNamespaces.b.d.kt
@file:JsQualifier("b")
package objectType.asTypeAliasInNamespaces.b
external fun bar(): a.I = definedExternally
but it should be:
File: objectType/asTypeAliasInNamespaces/a/asTypeAliasInNamespaces.a.d.kt
@file:JsQualifier("a")
package objectType.asTypeAliasInNamespaces.a
external interface I {
fun foo(): String
}
and
File: objectType/asTypeAliasInNamespaces/b/asTypeAliasInNamespaces.b.d.kt
@file:JsQualifier("b")
package objectType.asTypeAliasInNamespaces.b
external fun bar(): objectType.asTypeAliasInNamespaces.a.I = definedExternally
Example:
declare class Foo {
200?: string;
300: number;
}
becomes:
external open class Foo {
open var `200`: String = definedExternally
open var `300`: Number = definedExternally
}
but it fails with Kotlin compile error "Name contains illegal chars that can't appear in JavaScript identifier"
using Kotlin 1.2.70.
Either Kotlin needs to be fixed to allow them or else they should be omitted (possibly commented out).
Note: Even @JsName won't support numeric literals.
Kotlin files with types for react converted from @types/react
have a lot of issues,
react
Converting node_modules/@types/react/index.d.ts ts2kt: "NamespaceExportDeclaration" kind unsupported yet here! (node_modules/@types/react/index.d.ts:31:16 to 32:27) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:40:30 to 40:31) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:40:33 to 40:76) ts2kt: "Identifier" kind unsupported yet here! (node_modules/@types/react/index.d.ts:140:20 to 140:30) ts2kt: "Identifier" kind unsupported yet here! (node_modules/@types/react/index.d.ts:142:20 to 142:29) ts2kt: "Identifier" kind unsupported yet here! (node_modules/@types/react/index.d.ts:156:20 to 156:30) ts2kt: "Identifier" kind unsupported yet here! (node_modules/@types/react/index.d.ts:160:20 to 160:29) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:237:32 to 237:40) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:237:48 to 237:77) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:263:32 to 263:40) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:263:48 to 263:68) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:265:39 to 265:47) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:265:55 to 269:6) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:279:20 to 279:21) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:279:23 to 279:46) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:280:40 to 281:61) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:281:62 to 281:88) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:281:88 to 282:38) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:282:38 to 283:43) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:283:43 to 284:35) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:284:35 to 285:30) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:288:36 to 295:6) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:297:43 to 297:44) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:297:52 to 300:6) ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/react/index.d.ts:3256:85 to 3257:14) ts2kt: "ComputedPropertyName" kind unsupported yet here! (node_modules/@types/react/index.d.ts:3298:30 to 3298:41) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:3298:41 to 3298:43) ts2kt: "ExpressionStatement" kind unsupported yet here! (node_modules/@types/react/index.d.ts:3298:46 to 3298:62) ts2kt: "StringLiteral" kind unsupported yet here! (node_modules/@types/react/index.d.ts:3485:99 to 3486:18) ts2kt: Can't merge classifiers with different type parameters -- klass: open class Component<P, S>(props: P? = definedExternally /* null */, context: Any? = defi nedExternally /* null */) { open fun <K : keyof, S> setState(f: (prevState: S, props: P) -> Pick<S, K>, callback: (() -> Any)? = definedExternally /* null */): Unit = definedExternally open fun <K : keyof, S> setState(state: Pick<S, K>, callback: (() -> Any)? = definedExternally /* null */): Unit = definedExternally open fun forceUpdate(callBack: (() -> Any)? = definedExternally /* null */): Unit = definedExternally open fun render(): dynamic /* JSX.Element | Nothing? | Any /* "null" */ */ = definedExternally open var props: Readonly<
T$0> /* Readonly<
T$0> & Readonly<P> */ = definedExternally open var state: Readonly<S> = definedExternally open var context: Any = definedExternally open var refs:
T$1` = definedExternally
}
, iface: interface Component
Save declarations:
types/react/index.kt
types/react/index.React.kt
types/react/index.global.JSX.kt`
react-dom
ts2kt version: 0.0.14
Converting node_modules/@types/react-dom/index.d.ts ts2kt: "NamespaceExportDeclaration" kind unsupported yet here! (node_modules/@types/react-dom/index.d.ts:1:1 to 10:30) ts2kt: "ImportDeclaration" kind unsupported yet here! (node_modules/@types/react-dom/index.d.ts:10:30 to 16:16) Nothing was converted
ts2kt version: 0.1.3
There are issues with inheritance (missing override
keyword) in the code generated from phaser.d.ts (https://github.com/photonstorm/phaser3-docs/blob/master/typescript/phaser.d.ts).
Some definitions override parents' functions:
class Curve {
getStartPoint<O extends Phaser.Math.Vector2>(out?: O): O;
...
}
class Line extends Phaser.Curves.Curve {
getStartPoint<O extends Phaser.Math.Vector2>(out?: O): O;
...
}
That results in quite a similar kotlin code:
external open class Curve(type: String) {
open fun <O : Phaser.Math.Vector2> getStartPoint(out: O? = definedExternally /* null */): O = definedExternally
...
}
external open class Line : Curve {
open fun <O : Phaser.Math.Vector2> getStartPoint(out: O? = definedExternally /* null */): O = definedExternally
...
}
The function Line.getStartPoint
hides member of supertype Curve
so should be marked with override
keyword.
Examples:
external interface MyFunction {
@nativeInvoke
fun invoke(a: Int, b: String): Int
}
inline fun MyFunction(f: (a: Int, b: String) -> Int): MyFunction {
return f.unsafeCast<MyFunction>()
}
external interface MyFunctionWithVararg {
@nativeInvoke
fun invoke(a: Int, vararg b: String): Int
}
inline fun MyFunction(f: (a: Int, b: String) -> Int): MyFunctionWithVararg {
return { a -> f(a, js("arguments").slice(1)) }
}
Running https://github.com/photonstorm/phaser-ce/tree/master/typescript through ts2kt produces invalid Kotlin headers. All definition files convert without errors, with the exception of "box2d.d.ts" which prints the following:
ts2kt: "PrefixUnaryExpression" kind unsupported yet here! (typescript/box2d.d.ts:307:20 to 307:23)
ts2kt: "PrefixUnaryExpression" kind unsupported yet here! (typescript/box2d.d.ts:330:20 to 330:23)
ts2kt: "PrefixUnaryExpression" kind unsupported yet here! (typescript/box2d.d.ts:348:20 to 348:23)
ts2kt: "PrefixUnaryExpression" kind unsupported yet here! (typescript/box2d.d.ts:384:21 to 384:24)
To save you some time I have attached the generated header files. They were generated with ts2kt v0.0.12.
Example:
declare class ExpectedOverrides {
equals(a);
hashCode(): number;
toString();
}
becomes:
external open class ExpectedOverrides {
override fun equals(a: Any): Unit = definedExternally
override fun hashCode(): Number = definedExternally
override fun toString(): Unit = definedExternally
}
which doesn't compile. It should be:
external open class ExpectedOverrides {
override fun equals(a: Any?): Boolean = definedExternally
override fun hashCode(): Int = definedExternally
override fun toString(): String = definedExternally
}
ts2kt version: 0.1.3
There are issues with imports in the code generated from phaser.d.ts (https://github.com/photonstorm/phaser3-docs/blob/master/typescript/phaser.d.ts).
Definition uses namespaces, for example:
declare namespace Phaser {
namespace Actions {
function GridAlign<...>(items: G, options: GridAlignConfig): G;
...
}
}
That results into phaser.Phaser.Actions.kt
and external fun <...> GridAlign(items: G, options: GridAlignConfig): G = definedExternally
The problem is GridAlignConfig
is defined as declare type ...
on top-level and resulting kotlin interface is generated to phaser.kt, default package. So should be imported explicitly.
Automatic intention "import" is being sonw but doesn't work on this error (seems due to default package). Maybe it's related somehow.
I run ts2kt on react native and I get the following output:
ts2kt react-native.d.ts
Converting react-native.d.ts
ts2kt: "TupleType" kind unsupported yet here! (react-native.d.ts:1728:25 to 1746:6)
ts2kt: "TupleType" kind unsupported yet here! (react-native.d.ts:1748:32 to 1753:6)
ts2kt: "TypeQuery" kind unsupported yet here! (react-native.d.ts:3548:16 to 3548:34)
ts2kt: "TypeQuery" kind unsupported yet here! (react-native.d.ts:3549:18 to 3549:38)
ts2kt: "TypeQuery" kind unsupported yet here! (react-native.d.ts:3550:17 to 3550:36)
ts2kt: "TypeQuery" kind unsupported yet here! (react-native.d.ts:3551:19 to 3551:40)
ts2kt: "TypeQuery" kind unsupported yet here! (react-native.d.ts:3552:18 to 3552:38)
ts2kt: "TypeQuery" kind unsupported yet here! (react-native.d.ts:3553:20 to 3553:42)
ts2kt: "TypeQuery" kind unsupported yet here! (react-native.d.ts:3554:27 to 3554:56)
ts2kt: "TypeQuery" kind unsupported yet here! (react-native.d.ts:3555:26 to 3555:54)
ts2kt: "TupleType" kind unsupported yet here! (react-native.d.ts:6179:68 to 6179:85)
ts2kt: "TupleType" kind unsupported yet here! (react-native.d.ts:6179:107 to 6179:123)
ts2kt: "TupleType" kind unsupported yet here! (react-native.d.ts:7652:32 to 7652:57)
Save declarations:
./react-native.kt
./react-native.global.kt
When you look at the generated code, it's just using dynamic instead of the provided type:
external interface TimerMixin {
var setTimeout: dynamic /* "TypeQuery" kind unsupported yet here! (react-native.d.ts:3548:16 to 3548:34) */
var clearTimeout: dynamic /* "TypeQuery" kind unsupported yet here! (react-native.d.ts:3549:18 to 3549:38) */
var setInterval: dynamic /* "TypeQuery" kind unsupported yet here! (react-native.d.ts:3550:17 to 3550:36) */
var clearInterval: dynamic /* "TypeQuery" kind unsupported yet here! (react-native.d.ts:3551:19 to 3551:40) */
var setImmediate: dynamic /* "TypeQuery" kind unsupported yet here! (react-native.d.ts:3552:18 to 3552:38) */
var clearImmediate: dynamic /* "TypeQuery" kind unsupported yet here! (react-native.d.ts:3553:20 to 3553:42) */
var requestAnimationFrame: dynamic /* "TypeQuery" kind unsupported yet here! (react-native.d.ts:3554:27 to 3554:56) */
var cancelAnimationFrame: dynamic /* "TypeQuery" kind unsupported yet here! (react-native.d.ts:3555:26 to 3555:54) */
}
Example:
methodWithInOutArg?<A>(n: A): A;
becomes:
val <A> methodWithInOutArg: ((s: A) -> A)? get() = definedExternally
which fails with compile error "Type parameter of a property must be used in its receiver type".
It should be something like the following (with or without the comments):
val methodWithInOutArg: ((s: Any /* A */) -> Any /* A */)? get() = definedExternally
After generation kotlin stubs for react material-ui (ts2kt v0.0.20, material-ui v0.20), runtime results:
src/material/index.__MaterialUI.kt:339:33: error: unresolved reference: React
external interface PaperProps : React.HTMLAttributes<Any>, React.Props<Paper> {
^
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.