Angular 2 for 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?

1 Like