Git Product home page Git Product logo

Comments (6)

Daninet avatar Daninet commented on July 20, 2024

It does have .d.ts files for the compiled bundles. They are pushed to NPM and it's also visible here on GitHub in the binaries branch. https://github.com/Daninet/gmp-wasm/tree/binaries/types/src
https://www.jsdelivr.com/package/npm/gmp-wasm?path=dist%2Ftypes%2Fsrc

Is there an extra step which needs to be done in order to make it work with Kotlin?

from gmp-wasm.

danwallach avatar danwallach commented on July 20, 2024

Ahh, I didn't see that, because I was looking at the GitHub source. I'll figure this out. Supposedly, Kotlin has a tool that reads these declaration files.

from gmp-wasm.

danwallach avatar danwallach commented on July 20, 2024

Well this is disappointing. The automatic TS to Kotlin interface extractor is... not very good. Like, it didn't notice any of the methods on an Integer, although it did figure out the GMPLib to Context part.

Like, this is the entirely of its extracted interface for Integer:

external interface IntegerFactory : IntegerFactoryReturn

external interface Integer : IntegerReturn

typealias OutputType<T> = Any

external enum class DivMode {
    CEIL /* = 0 */,
    FLOOR /* = 1 */,
    TRUNCATE /* = 2 */
}

Very disappointing. I can't tell you whether this is a problem on the TypeScript side (which I don't really understand) or with the Kotlin side (where the relevant tool is considered "alpha quality".

from gmp-wasm.

Daninet avatar Daninet commented on July 20, 2024

The TypeScript interface works perfectly, I use it in production code.

The TypeScript declaration file looks like this.

declare type OutputType<T> = T extends number ? Integer : T extends Integer ? Integer : T extends Rational ? Rational : T extends Float ? Float : never;
export declare enum DivMode {
    CEIL = 0,
    FLOOR = 1,
    TRUNCATE = 2
}

I guess Kotlin cannot understand this more complicated declaration at OutputType which is required in order to have correct correct type inference when doing operations on mixed types. (Integer + Rational = Rational, Integer + Float = Float, etc...)

from gmp-wasm.

danwallach avatar danwallach commented on July 20, 2024

The Kotlin is vaguely equivalent to the part you quoted, but what's missing is all of the actual methods on Integer (add, subtract, multiply, etc.). They're just not there in the generated Kotlin wrappers.

Needless to say, this means that I either have to do all that myself (error-prone, fragile, etc.), or I have to wait for the Kotlin tools to mature a bit.

from gmp-wasm.

danwallach avatar danwallach commented on July 20, 2024

I've managed to figure out how to run dukat (the TypeScript-to-Kotlin interface extractor) manually and clean up its output, so I'm going to close this for now.

from gmp-wasm.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.