Git Product home page Git Product logo

java-ts-bind's Introduction

TypeScript binding generator for Java

java-ts-bind takes your Java source code and generates TypeScript types for it. It is meant to be used with GraalJS to provide a strongly-typed scripting environment.

This project was created for CraftJS, a Bukkit plugin for writing plugins in JavaScript. It is based on earlier work by Ap3teus.

No releases are currently provided. If you need it, compile it yourself (or open a bug in the issue tracker).

Usage

This is a command-line application.

  • --format: output format
    • Currently only TS_TYPES is supported
  • --in: input directory or source jar
  • --symbols: symbol sources (compiled jars)
  • --repo: Maven repo to fetch the source jar from
  • --artifact: Artifact to fetch from given repo
    • tld.domain:artifact:version (Gradle-style)
  • --offset: path offset inside the input
    • Mainly used for Java core types; see .github/workflows for an example
  • --include: prefixes for included paths
    • By default, everything is included
  • --exclude: prefixes for excluded paths
    • Processed after includes; nothing is excluded by default
  • --blacklist: blacklisted type fragments
    • Types that have names which contain any of these are omitted
    • Methods and fields that would use them are also omitted!
  • --packageJson: read these options from a JSON file
    • The options should be placed under tsbindOptions object
    • Names of options lack -- prefixes but are otherwise same
    • Handy when you already have package.json for publishing
  • --index: generate index.d.ts that references other generated files

Limitations

java-ts-bind does not necessarily generate valid TypeScript declarations. The results are good enough to allow strongly-typed scripts, but it is recommended that noLibCheck is used.

Please also note that java-ts-bind provides only the types. Implementing a module loading system for importing them is left as an exercise for the reader. For pointers, see CraftJS which (at time of writing) implements a CommonJS module loader with Java and TypeScript.

java-ts-bind's People

Contributors

bensku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

java-ts-bind's Issues

ES6 Map interop

GraalJS supports using ju.Map as ES6 Map now, let's use it. This is already done for lists, so should be quick.

Use TS class types

TypeScript represents references to classes as constructor types. Emitting them for method argument types should be reasonably easy, because constructor parameters can be ignored. For returned values, it is much more difficult and probably not worth the effort.

Type blacklist

Add support for blacklisting types. Fields and methods which have blacklisted types in their signatures should not be generated.

License?

Hello!

I'm interested in using this project, but I noticed the project does not have a LICENSE file, is it located elsewhere or maybe an oversite?

Thanks! ๐Ÿ™‚

Lambda compatibility

Passing JS functions as implementations of Java functional interfaces is supported by GraalJS. Generated types don't support this.

TypeScript interfaces

Use TS interfaces to represent Java interfaces. Getters/setters in them need to be transformed to (readonly) fields.

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.