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

Embed types into the source code #313

Open
JonathanDagan opened this issue Mar 9, 2023 · 9 comments
Open

Embed types into the source code #313

JonathanDagan opened this issue Mar 9, 2023 · 9 comments

Comments

@JonathanDagan
Copy link

Embed types into the source code and not only into the bodybuilder.d.ts file which would be easier to maintane with further changes to the API.

Currently im trying to use es6 imports and using the bodybuilder object and it seems to be a lot more trouble than it needs to be in a typescript project imo.

I would like to start working on migrating to ts this weekend but would first want to know if it is even desierd and secoundly if there are any prerequists to start working on this issue.

I would like to add better support to ts in this project since I was about to consider not using it in the project im working on atm but this project is a great idea and for me the TS support is a bit lacking for my use.

Thanks in advance, John :)

@johannes-scharlach
Copy link
Collaborator

@johnnyraphic Take a look at https://github.com/johannes-scharlach/elasticbuilder

2 years ago I did an almost complete re-write of bodybuilder in TS while copying most of the tests from this project. And since bodybuilder hasn't really changed since then this should still be up to date.

You can think of that project as a major update to bodybuilder with a breaking API change (and without any testing in production so far).
What's missing to merge it back into this project is backwards compatibility to the (very versatile) bodybuilder API. I believe that that's actually possible, so if you want to make bodybuilder work with TS, that's probably the easiest path.

@danpaz
Copy link
Owner

danpaz commented Mar 10, 2023

FWIW I'd be fully supportive of this, it's been a while since the TS type definitions were added and there for sure is room to improvement.

Is it possible to implement this in pieces instead of a complete rewrite? e.g. with allowJs: true in tsconfig

@johannes-scharlach
Copy link
Collaborator

Back when I did that rewrite, I saw no good way to get started on a gradual approach. I don't recall all the details why and now when you compare my rewrite with bodybuilder, you see that the file structure is very similar.

It might be possible to compare the two repos and figure out some ways to do this gradually.

I have in the end completely changed the way data is represented internally in the builders without affecting the external API. There because the internal state within bodybuilder isn't covered with any JSDoc types.

@JonathanDagan
Copy link
Author

@danpaz To be honest you could do something like you suggested with allowing js to do a partial migration but tbh i don't see why you would like to do that since the code base isn't that big imo to go for that approach since it would be more of a hindrance than helpful imo.

Is there any reason I'm missing here with the partial migration to TS?

@danpaz
Copy link
Owner

danpaz commented Mar 11, 2023 via email

@JonathanDagan
Copy link
Author

so I would recommend that we create a ts migration branch or something in the repo and than we can create multiple PRs just as you said and that would be more manageable to that branch and once that branch is ready we will merge it to the master branch and create a new release that supports es import properly

@danpaz
Copy link
Owner

danpaz commented Mar 11, 2023

👍 sounds good! Thanks for kicking this off

@JonathanDagan
Copy link
Author

Sure thing :)

I'll wait for you to create the branch and you can tag me or something and ill start working on that.

I would recommend that if you have any specification as to how you would like stuff to be typed or as to how stuff would look out, to write it out before people would start working on that to try and make this as efficient as possible.

@danpaz
Copy link
Owner

danpaz commented Mar 11, 2023

Branch is created: https://github.com/danpaz/bodybuilder/tree/ts-migration

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

No branches or pull requests

3 participants