DEV Community

Discussion on: How to UPPER_CASE to camelCase in raw Typescript generics

Collapse
 
faiwer profile image
Stepan Zubashev

That's pretty interesting. Thank you for the article.

But I think it'd be better to add a note that this solution isn't recommended in real world projects, because it might slow down the compilation process dramatically. Because this Type-Engine needs to interpretate all these types symbol-by-symbol, and if you have a plenty of them, it's better to write those types manually or by means code-generating.

We have in our applications several hundreds of types that we'd like to automatically convert from snake_case to camelCase. But we still wait until TS will support it properly (like it does with UPPERCASE and lowercase). Because the compilation process is too slow even without it :-D

But for small projects or small amount of types it solves the task.

Collapse
 
svehla profile image
Jakub Švehla

Yeah, 😄 you're right that this solution is not too fast and TS checked could be pretty stuck on large codebases projects.

I think that there is the other side of the coin if you look at the static types as an alternative for "unit tests" (especially for smaller codebase where 100% accuracy code is not needed). So it's pretty good to have only one source of truth in your codebase instead of taking care of your .js files and your tests (.spec.js|.test.js) files.

Another nice feature of this solution is that you can remove it and replace upper code with a simple any and your runtime javascript will still be Okey :D

But I have to agree that efficiency is not the best one... :(