Objection.js: Maintainers interested in a typescript PR?

Created on 4 Oct 2018  路  7Comments  路  Source: Vincit/objection.js

I know it's a lot to ask, but I just want to start some discussion on this topic. What do the maintainers think about adding types with typescript? @koskimas ? Would you be open to typescript?

Many projects in the node ecosystem migrate to TS these days and IMHO it would benefit objection.js greatly if it was written in typescript. It's the perfect usecase for it-a big codebase utilising classes.

One very immediate upside would be typings-they'd get generated from the codebase for free-no need to manually edit them.

Most helpful comment

When I write java, c++ or any other strongly typed language, I use very different patterns and practices. Designing a library using a dynamically typed language, like javascript, and then forcing types on top of that is simply idiotic. I'm not saying typescript is idiotic. I'm saying in order to write good typescript code, the codebase project should be designed with typescript in mind from the beginning.

This is why external typescript typings for many javascript libraries (including objection) are super complex and ugly.

All 7 comments

Oh, you mean rewriting the whole thing with typescript? Yeah, nope. Too much work with too little gain at this point.

I've been trying to port just the documentation to use vuepress for the last six months, and even that is taking effort away from features and bugfixes.

@koskimas when you put it like "rewriting" whole thing it sounds very painful. But in reality it is just about renaming all files to ts and sprinkling interfaces/types onto function arguments and function return types. Most of those are already defined in the TS definition which was created manually.
Last thing would be to add a build step to npm prepare script.

You don't have to touch tests at all-it's considered a normal practice to have tests in JS.
So it's really not that much work. IMHO it could be done in the matter of 1 or 2 days.

If you'd like, I can open a PR. With this issue I just want to know if you like typescript or not.

I'll rename this into a more proper name.

It's not that simple. Objection takes advantage javascript's dynamic nature in pretty complicated ways. Typing those would be super ugly and painful, if not impossible. For example, see the issue about typing custom query builders.

To take advantage of the good parts of typescript, we would really need to rewrite most of objection. Only adding types where it's easy to do, would only introduce the bad parts (compilation phase) and very little of the good parts (type safety). Most of the stuff would still have any type.

When I write java, c++ or any other strongly typed language, I use very different patterns and practices. Designing a library using a dynamically typed language, like javascript, and then forcing types on top of that is simply idiotic. I'm not saying typescript is idiotic. I'm saying in order to write good typescript code, the codebase project should be designed with typescript in mind from the beginning.

This is why external typescript typings for many javascript libraries (including objection) are super complex and ugly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

purepear picture purepear  路  3Comments

AhmadRaza786 picture AhmadRaza786  路  3Comments

haywirez picture haywirez  路  3Comments

nazar picture nazar  路  3Comments

njleonzhang picture njleonzhang  路  4Comments