Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish TypeScript typings #285

Open
danvk opened this issue Sep 6, 2016 · 19 comments
Open

Publish TypeScript typings #285

danvk opened this issue Sep 6, 2016 · 19 comments
Milestone

Comments

@danvk
Copy link

danvk commented Sep 6, 2016

There are some type definitions available on DefinitelyTyped, but they're woefully incomplete (they only cover jsts.geom and parts of jsts.io). An official set of type definitions would be a big usability win for TypeScript users and a documentation win for everyone.

@bjornharrtell bjornharrtell added this to the Future milestone Sep 6, 2016
@bjornharrtell
Copy link
Owner

An interesting project would be to translate the upstream source directly to TypeScript.

@Montago
Copy link

Montago commented May 31, 2017

So... any news on TypeScript ?

the TypeDef available on DefinitlyTyped are incomplete :-(

@bjornharrtell
Copy link
Owner

bjornharrtell commented May 31, 2017

I currently have no personal interest in bindings, but I would love to target TypeScript directly using similar code transformation as I did for ES5. However it will require non-trivial efforts which I as of yet have not planned.

@HarelM
Copy link

HarelM commented Jun 4, 2021

Hi,
I'm currently using turf in my frontend and NTS in my backend.
I'm failing to find a good way to project a point onto a line segment in turf in order to find the closest point on a line (I know I can write this code, but I prefer to use a tested library instead...), and since I'm used to working with NTS (.net port of JTS) I thought I might switch to use this library.
However, I was wondering what's the status of typescript typings and the ability to import only what I need (linked issue) to make sure the production code stays small.
Thanks ahead! If I can help in the effort of migrating this library to TypeScript let me know...

@AnderssonPeter
Copy link

@HareIM doesn't https://turfjs.org/docs/#nearestPointOnLine do what you are asking for?

@HarelM
Copy link

HarelM commented May 20, 2022

Reading the docs and finding out that you had a typo when you run the code you copied poorly is not the same as having typescript guard you when you write the code. :-)
I've migrated MapLibre to typescript and it helped a lot both to the community and the maintainers.

@AnderssonPeter
Copy link

Yes typescript is a life saver, sadly jsts is unusable in a typescript environment without correct typings.

@bjornharrtell
Copy link
Owner

It's definitely doable, but I still have no pressing need myself.

@PauloSSAragao
Copy link

An interesting project would be to translate the upstream source directly to TypeScript.

Hi Bjorn,
a lot of complex js libraries instead of migrate to typescript, they use jsdoc to generate the typescript types.
For instance, for cesiumjs library, they have adopted this approach: https://cesium.com/blog/2020/06/01/cesiumjs-tsd/

Here is a guide how to generate: https://dev.to/jor/jsdoc-to-typescript-declaration-19fg

In the cesiumjs code you can check the source code with the jsdoc tags: https://github.com/CesiumGS/cesium

@bjornharrtell
Copy link
Owner

@PauloSSAragao that implies correct jsdoc transpiled from JavaDoc, which I believe is about as difficult to transpile to as TypeScript and less verifiable.

@simonseyock
Copy link

@bjornharrtell I would find it interesting to investigate what would be needed in order to automatically generate typescript code from the java jts code. Would this be appreciated for this project? If so I would read into the bundler code and see how it could be modified to generate typescript as I don't see any library that could do this natively.

@bjornharrtell
Copy link
Owner

@simonseyock JSTS was made by transpiling patched Java upstream code (JTS) to JavaScript with use of my own custom transpiler which can be found at https://github.com/bjornharrtell/java2estree made in Scala. It's pretty hacky stuff, so be warned. But it should be possible to hack it some more to output TypeScript instead. But it is no trivial task and requires Scala knowledge. I still have some interest in this and would welcome efforts.. my own priorities do not allow a large investment at this time.

@simonseyock
Copy link

Ok, I might have some time at hands in the near future and will start looking into this. I do not know Scala, but I worked with functional programming languages before and also other languages on the java VM. So it might be interesting to try it out..

@bjornharrtell
Copy link
Owner

I've had some fun modernizing https://github.com/bjornharrtell/java2estree a bit.. and realized there is a problem with regard to this issue. The way java2estree works is by generating AST in estree format which is then transformed to JavaScript using a third party tool called astring. For TypeScript this will be have to be replaced by something equivalent and I'm not even sure that exists.

@Montago
Copy link

Montago commented Jul 14, 2023

You dont need to translate the whole library, only make the types documents that describe objects, return types and methods ..etc..

This is enough to include the js lib and use it in typescript

Given that Java is type strong, you only need to scratch the surface..

Creating a library scraper shouldnt be too hard a challenge for a seasoned programmer

@bjornharrtell
Copy link
Owner

@Montago you are saying that a viable path is to generate typescript type definitions directly from Java using some entirely other means of translation vs. the source to source translation? I think you underestimate what would be required to do so and get a result that is corresponding to the source to source translation.

@bjornharrtell
Copy link
Owner

Hmm looks like there is some kind of more or less official TypeScript AST and the TypeScript compiler can turn that into code (see https://stackoverflow.com/questions/65213952/how-to-generate-code-from-ast-typescript-parser). Looks pretty promising actually!

@bjornharrtell
Copy link
Owner

Food for thought, typescript-eslint/typescript-eslint#7228.

@simonseyock
Copy link

If the typescript compiler can be used, that is definitely the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants