r/typescript • • Sep 02 '26

Manage Model

Am I the only one who had a problem with how separated the data manipulation is?

Creating something in different ways (eg. create a chat message from only a text or creating from an api response ) Defaults in 3 files, parsing, validation, and sorting everything inline just to search it up later and copy it.

My solution? Put stuff like that in one place: See the screenshots.

Basically define all that sh in one place and just use:

userModel.parser.db.from(response)

habitModel.inits.createFromTitle("Do a blackflip")

people.sort(peopleModel.sorters.lastCreated)

https://github.com/dozsolti/manage-model

0 Upvotes

22 comments sorted by

View all comments

Show parent comment

1

u/theZozole Sep 02 '26

I see, libraries like zod, lodash, date-fns will work great.

The idea is that with manage-model you have all your validations (yes, you can do that with zod) but you also have every defaults, formatter (to api calls, to db, microservices) migration functions etc everything in single place, instead of scattered across the project. Removing the need for searching, cod duplication, not knowing if somebody added or changed something.

All the logic extracted in a single place. File might get a big long yes, but you can always split and it's easier to work with 2 files than 5-10lines each in 100 different files

4

u/bodimahdi Sep 02 '26

Cool, good luck with your library! A final piece of tip is if you’re really committed to it you should make your README file more comprehensive. You know add more examples instead of only parsing and validating example.

1

u/theZozole Sep 02 '26

Thank you, will do.

Got a few downvotes but I think it's mainly because the people don't understand the real purpose of these 10 lines of typescript

2

u/bodimahdi Sep 02 '26 edited Sep 02 '26

Eh they do but they do not need it or have better alternatives/approaches. That’s why you should make your docs more comprehensive to make users really see what you’re package is trying to solve. And if someone needs it they will use it. It’s as simple as that.