DEV Community

Cover image for Why Beginners CRUSH IT with TypeScript

Why Beginners CRUSH IT with TypeScript

Sohail SJ | chakraframer.com on November 19, 2024

If you're just starting your coding journey or looking to level up your skills, you might be wondering whether to learn JavaScript or TypeScript. J...
Collapse
 
pengeszikra profile image
Peter Vivo

Typescript is not bad at the end but JSDoc is fare more versatile, compatible with TS, even use TS types from TS module, but can work without compiling. JSDoc vs TS

Collapse
 
asmyshlyaev177 profile image
Alex

JSDoc can't enforce type checks like TS, without enforcing half of the team won't care.
Bigger the team - more benefits from Typescript.
I used to be a TS hater and advocated for JSDoc once.

Collapse
 
pengeszikra profile image
Peter Vivo

JSDoc can also configure to force type check, without extra // @ts-check

Thread Thread
 
asmyshlyaev177 profile image
Alex • Edited

With tsc ? No, thanks, JSDoc is for documentation, can put examples and links there.

Can't put more or less complex types in JSDoc btw, generics for example, maybe on closure compiler only, debug types also harder.

Thread Thread
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

JsDoc can’t replace TS and using it with TS is just great for big teams

Thread Thread
 
pengeszikra profile image
Peter Vivo

JSDoc can use all complex type solution, even generic: (take look this npm module, written in JSDoc)[npmjs.com/package/jsdoc-duck]

Thread Thread
 
asmyshlyaev177 profile image
Alex • Edited

Less than 100 LOC, and seems like nobody uses it. Not a good example.

Types will never be fully properly supported in JSDoc.
github.com/microsoft/TypeScript/is...
github.com/microsoft/TypeScript/is...

I tried to use JSDoc for types myself, it's a pain, and no benefits, way worse than Typescript.
But good to put usage examples and link to docs there

Image description

Thread Thread
 
pengeszikra profile image
Peter Vivo

Thx for your comments.
I brought to table that npm module, because a first I created a good reason - make a useReducer typesafe and easier handle. I don't beleive a too many code lines if problem can be solved a much lighter way.
Main reasion this npm module is proof the JSDoc Generic working perfect and make a life easier.

user declared actions union types -> jsdoc-duck -> typed: [state, action functions]
Enter fullscreen mode Exit fullscreen mode

I even know hard to argue the typesafe useReducer is a valuable stuff, or even hard to argue react is neccecary framework for so many project, currently I try explore the pure html development instead using any freamwork - that why don't spend time to improve that library.

On pure html the JSDoc also hyper helpfull.

Thread Thread
 
asmyshlyaev177 profile image
Alex

Reinventing the wheel every time is a bad idea. Way easier when you have framework/tool and documentation with stack overflow answers.
You will get it if you work on a bigger project with many people.

Thread Thread
 
pengeszikra profile image
Peter Vivo • Edited

Good advice. Maybe easier way still exist, maybe sometimes worth to try another way. I am work on a bigger project with many people ( bit legacy react stuff - 3-7yeard old code ). This is push me to JSDoc direction, because in this project we don't have option to rewrite a full code to TS.

Pure HTML way comming: our deployment process is painfull slow on AWS, so I trying what is the difference between no build, no compile, no framework coding vs. standard framework using. And my first impression is surprising fine, like the lost your chain. ( dependency chain )

Thread Thread
 
asmyshlyaev177 profile image
Alex

Can enable allowJs and start rewriting file by file, obstacle if it is management decision.

I remember how Frontend development started, it was pure JS + JQuery, no frameworks. People started to invent things, it was so messy that can't possibly figure out somebody else code if everything written from scratch. That how frameworks got popular. Frameworks gives solution to very common tasks and make code somehow readable.
AWS is a problem, builders are fine, things like Vite at least fast enough, only Next.js still slow af.

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Actually JSDoc is great option if you want suggestions without committing to ts and its sometimes complicated type errors. I do use JSDoc in Ts or Js project for documentations of helpers and utilities

Collapse
 
dainiuss profile image
Dainius Stepulevicius

It's easy to forget that just because you are writing typescript it's just same old dodgy JavaScript at runetime with many many weird edgecases!
Not learning Javascript is like saying you are chef if you can make yourself breakfast.

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Cant agree more

Collapse
 
ks_4ef2e5f4b profile image
Kiran Sarpotdar • Edited

Vanilla Javascript is much simpler yet efficient and if one has good programming skills and does coding properly, it's very fast. No need to typecast all variable.s in fact that's strength of JavaScript. Why to add layers on the language which is interpreted and then make it compiled language.

Collapse
 
brense profile image
Rense Bakker

So you get less runtime errors... And yes, that happens a lot. People change function implementations all the time. If some function return type changes and your code that uses that function expects an object with a certain property to be returned and its suddenly not available anymore, you're dead.

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Thats a very good point. TS is must have for such refactoring

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Today only i was building a temporary server. Started with js and then realised i have keep types of functions parameters in check and altered the files to index.js to index.ts 😂😂😂

Collapse
 
c_k_c6c7156c1f991203855d0 profile image
C K

IMO, JavaScript's implicit nature is much easier to learn than TypeScripts explicit nature.

JavaScript's makes it easier for beginners to jump into coding without needing to understand types or deal with strict errors. Especially for smaller projects they are typically working on, TypeScript can feel like over engineering.

I personally stay away from TypeScript because I can write my own JavaScript, thank you. And because I'm cognizant that dynamic typing is not a crutch, but a super power.

This one's obvious. JavaScript's ability to inherently operates without requiring additional type annotations and configurations upfront, which can slow down prototyping.

Also, JavaScript can "Just get it working" quickly, running directly in browsers or environments like Node.js without a compile step like TypeScript requires.

Also, JavaScript's polymorphisms is seamless, built-in without needing to configuring overloads or generics. While TypeScript can do this with any or unions, it's a conscious choice rather than an automatic and natural behavior.

In a nutshell, JavaScript defaults to flexibility and makes it more natural to fit where dynamic behavior is a first-class requirement. Its superpower is the ability to keep things simple and dynamic and never enforce structures unless it is really necessary.

Thanks for the article.

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

I agree with your point about the "compile step" and the initial configuration challenges of TypeScript—I’ve spent a fair amount of time getting it right myself.

That said, I don’t see myself going back to JavaScript. TypeScript has saved me from countless bugs, especially those caused by simple typos. And when it comes to refactoring, TypeScript is a game-changer.

I do a lot of refactoring since I’m often the one maintaining the codebase in most of the projects I work on. With TypeScript, I can make sweeping changes confidently, knowing the type system will catch any mistakes.

For me, the upfront investment in setup and learning TypeScript pays off exponentially in the long run, especially for larger or long-lived projects.

Collapse
 
c_k_c6c7156c1f991203855d0 profile image
C K

I completely understand what you're thinking. Long term though, it's a Microsoft language. They will force you to upgrade some historically speaking.

Thread Thread
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

lol so true

Collapse
 
sahil_chaubey_45db49be580 profile image
WebDevWarrior

Great insights! I'm curious, is it worth starting with TypeScript for a small project, or should I stick to JavaScript until I build something bigger?

Collapse
 
asmyshlyaev177 profile image
Alex

Best way to learn is by applying it.

Collapse
 
bugger279 profile image
Inder Sav

I use to hate TS, now I can't imagine going back to JS again. I recommend to start with TS right away.

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Feeling is mutual

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

definetly, start small for better trackability

Collapse
 
rushiljalal profile image
Rushil Jalal

Have you ever spent hours debugging a typo or a missing semicolon in your JavaScript code?

I thought JS doesn't require semicolons?

Collapse
 
asmyshlyaev177 profile image
Alex

Semicolon is needed, just most of the times JS can correctly assume it's location, but not always.

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Oh this is new to me. I will keep this in mind

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Thats an optional thing. it works with and without it. I prefer facing without semis

Collapse
 
devops_devrel profile image
Memories From

TypeScript definitely feels like a superpower after reading this! The gradual learning curve you mentioned is such a relief for beginners like me

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Happy that article helped with yo TS journey

Collapse
 
amitind profile image
Amit Yadav

Typescript with deno is also good start where you can just start using typescript without worrying about anything.

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Actually that’s a thought. I haven’t tried deno but i should now

Collapse
 
armando_ota_c7226077d1236 profile image
Armando Ota

Typescript FTW in JS world since people are writing such a sh*tty code its ridiculous.

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

We all start from JS. But yeah I cant imagine myself writing code without TS. Code auto complete and lint as big help avoiding ridiculous typos can make you waste 2 whole days.

Collapse
 
sahil_reigns_4776e181e6f7 profile image
ReignsEmpire

You’ve explained why TypeScript is such a game-changer

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

hey thanks

Collapse
 
sahil_chaubey_5417dfa7caa profile image
ReactNinja

How long do you think it takes to get comfortable with advanced TypeScript features like generics or utility types?

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

For me it took an 6 months window or learning and making, more you build better you get

Collapse
 
sahilchaubey profile image
sahilchaubey03

The resources you listed for learning TypeScript are gold! Thanks for not just explaining the 'why' but also giving us the 'how' to get started

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

Happy that they helped

Collapse
 
superdevchaurasia profile image
Ashfak

You mentioned Chakra UI and its TypeScript support—do you think it’s better for beginners than other UI frameworks?

Collapse
 
thesohailjafri profile image
Sohail SJ | chakraframer.com

I definitely think that