DEV Community

Discussion on: To Typescript Or Not To?

Collapse
 
fabd profile image
Fabrice D. • Edited

I just wish they stop adding gazillions of language features to JS and instead add some basic typing. Look at php it has some nice basic typing, it’s super easy to read. We need some basic typi g features in native Javascripts, just "good enough" would go a long mile over no typng at all, and a million times better than the insane levels of abstraction TypeScript creates.

Problem withTS is you’re not just learning TS. This is a fallacy, in fact you have to learn to master TS and you have to learn all the types for any library you use because of course there is always 50 different ways to type your library. Like, try using native dom with TS... you spend so much time figuring out what types in those .d.ts files you should use to do something. None if that is "self documenting"... you have to spend hours looking at other people’s code, and opening the declaration files. You’re really learning an entire layer of abstraction on top of the library you’re using in the first place.

If I used TS only with my own Javascript then we’re looking at an entirely different scenario. In that case I use TS however I want with more or less strict typing, and I don’t need to study how someone else created types.

Have you looked into types for eg. vue 3 ? It’s so over the top abstract imho, and there is no guide anywhere to tell you how to use them. You probably only need 10% of the types declared, since many of these are for the library’s internals... but the types are not sorted out for you (ie. internal utilities vs public consumption of the library). You have to trawl through these files and spend lots of time trial and error.

For me 95% of the worth of TypeScript is just to be able to declare a structure (like good old C structs), declare function params and return types.

Javascript needs a "loose" , "good enough" typing added to the native implementation, that would be much more accessible.