Kotlin 1.1 will use ts2kt for transform TypeScript definition of javascripts library in kotlin definition. But Angular 2 have native version of TS so don’t have definiton
So, will we have a Angular 2 port for kotlin?
Kotlin 1.1 will use ts2kt for transform TypeScript definition of javascripts library in kotlin definition. But Angular 2 have native version of TS so don’t have definiton
So, will we have a Angular 2 port for kotlin?
I just registered to ask exactly this question!
It would be super nice to write Angular 2 in Kotlin and possibly share data classes / DTOs or even some input validation logic with the backend code base.
I assume it won’t be impossible to generate typings from real typescript code which could then be used by ts2kt.
Angular 2 can also be used with pure JavaScript as far as I know.
Any news?
I think, there’s enough documentation about calling JavaScript code from Kotlin, so that anyone can write Kotlin headers. Right, it’s much more convenient when there’s another existing ones, or at least tool that can generate Kotlin headers from TypeScript headers. As for now, only converter exists, that does not often do it’s work good, but it’s enough to start. So why is community so reluctant? If you are really interested in trying Kotlin, why don’t you:
I realize that most of community members simply don’t have enough time for all this. I also hope that there are ones who have time and are ready to spend a little to try Kotlin with Angular, though I can’t see anyone. I guess there’s something else that stops people from trying. Is there’s something unclear with documentation? Or you suffer from IDE or compiler issues?
at least nothing stops rewriting Angular 2 in kotlin )))
BTW, it’s what I’m doing as my spare-time project. Note that it’s not in Kotlin and not in Kotlin JS in particular. It’s in Java, but fortunately Kotlin is supported as a JVM language. Here’s a TodoMVC application example: GitHub - konsoletyper/teavm-flavour-examples-todomvc
The problem is that Angular 2+ is write in TS and Kotlin can’t execute TS, only JS.
Yes, there is a Angula 2+ JS version, but the most community use TS, so we will need convert the TS version in Kotlin version, not the JS version.
I use some JS library in Kotlin and works fine, but big frameworks are the problem.
The problem is that Angular 2+ is write in TS and Kotlin can’t execute TS, only JS.
Angular 2+ is ideed written in TS, and then TS is transpiled to JS, right? You can easily call this JS from Kotlin. So you don’t need to execute TS from Kotlin.
How? Angular 2+ is compiled from TS to JS in the deploy, the framework and user code.
I can’t see where’s the problem. You can call JS code from Kotlin, all TypeScript eventually becomes JS, so you can call that JS. Please, provide a TypeScript code and show what problems you have calling functions defined in this TS code from Kotlin.
Here’s my example. Given initial TypeScript file:
function fib(n: number): number {
if (n == 0) {
return 1;
} else if (n == 1) {
return 1;
}
n -= 1;
var a = 1;
var b = 1;
for (var i = 0; i < n; i++) {
var c = a + b;
a = b;
b = c;
}
return c;
}
then I run
tsc -d fib.ts
ts2kt fib.d.ts
and get following Kotlin file:
external fun fib(n: Number): Number = definedExternally
(which I then can clean-up manually):
external fun fib(n: Int): Int
And then I can write my own simple Kotlin application that calls TypeScript function like this:
fun main(args: Array<String>) {
println(fib(5))
}
And, it works just fine! So what’s the problem to use Angular 2?
The problem is ngc - angular AOT compiler. It works only with typescript source (not javascript). Angular 2+ was designed with AOT compilation in mind. In dev mode, angular compiles templates and component/module metadata to javascript just at run time, in the browser. The generated code contains logic to render DOM elements, detect changes and dependency injection. In production, of course, it is recommended to compile this stuff at build phase - ahead of time. So, ngc is required to make production build.
So, using Angular 2+ (4.0.2 for now) is impossible without Kotlin implementation of Angular AOT compiler. For example there is angular branch for Dart with it’s own AOT implementation.
Unfortunately Kotlin is not yet suitable for dev mode too, due lack of persistent decorators support. If I understand correctly Kotlin doesn’t support javascript decorators at all…
To be honest: all javascript code is valid typescript code too. In theory this is possible to pass some js code to ngc, but, again, it requires classes and decorators (es7).
It will be cool, if Kotlin compiler support emitting es7 code (and typescript, as superset of it).
Good point on the ngc!
I found this project but… I don’t know how it works
technically it is possible but I found it not feasible to convert all those typescript types into headers
by the way you don’t need Angular to write Single Page Application (SPA).
I have an example here on how to write a single page application using Kotlin from scratch.
GitHub - techprd/spa-kotlin-js: Single Page App With Kotlin JS