What level of mastery do we need in JS before learning typescript.

Hello, quick question, what kind of mastery level do we need in JS before moving to learn typescript please. By the way, can someone explain why is it recommended to learn typescript please, like why not stay with JS everytime, what does typescript bridges?
36 Replies
Jochem
Jochem3mo ago
typescript adds some type checking and somewhat improves autosuggest the type checking is a bit complicated, as it happens on compile time (on your developer machine), and not at runtime, but it can be useful as for when to learn it? When you're comfortable with JS 🤷
Faker
FakerOP3mo ago
oh ok, type checking at compile type is just one of the functionality it provides but basically their is more to that? Since typescript exists, can we expect people to stop using JS at a certain point and just use typescript or both have use cases?
Jochem
Jochem3mo ago
typescript is only really useful to use as a language in a large team, or when you're writing a library for use by others and typescript compiles to javascript, so no, javascript isn't getting replaced
Faker
FakerOP3mo ago
oh ok I see, under the hood it's javascript just that using typescript is just a bit more syntax sugar than doing a bunch of complex things in JS to do the same thing?
Jochem
Jochem3mo ago
Hmm, it's more a development tool than a thing that does magic for you on the client side it helps you and your IDE to reason about the code so yeah, syntactic sugar is right, but it wouldn't be sensible to replace it by writing more javascript code by hand, not really
Faker
FakerOP3mo ago
yep I see, I have a better idea of what it is now, ty !
Ganesh
Ganesh3mo ago
I'm using typescript and I'm fairly early in learning it The main cause of headache are the packages Some have really complicated types that i don't understand My own types are pretty simple so working with my code is okay tho i might not be taking full advantage of ts
Rägnar O'ock
Rägnar O'ock3mo ago
basically TS is to JS what SASS or Less is to CSS (or C to ASM)] You write your code in a language that makes it easier to validate that what you want to do will actually happen like you expect it to and then compile that into the language that will be interpreted/executed by the computer there's not really a point at which you have to or you should learn it, theoricaly you could learn JS with TS, it would be a bit annoying because you could not just copy paste code into a browser console to test it but that would more or less be the only downside just so you get a good picture of it, TS is a superset of JS, that means that if you write valid JS, you also write valid TS. so moving from JS to TS can be pretty transparent at the start and you can then slowly incorporate TS stuff into your codebase
Faker
FakerOP3mo ago
yep I see
Rägnar O'ock
Rägnar O'ock3mo ago
as for what you should use it for, I would say if you use a framework or if you are writing code that will be used by someone else you should consider it. there's no "you have to" rules tho tho if you publish a lib it's a good idea to have type declarations available for it (basically the description of the API of the lib) as it makes using the lib waaaaaay easier even for people that will use it in JS only (IDEs and code editors actually run TS in the background for JS files most of the time) as Jochem pointed out, there's no plans to phase out JS any time soon, however TS is usually a testing grounds for new syntaxes and such that are suggested to TC39, the organism in charge of the evolution of JS. since TS started, JS has been slowly incorporating parts of it into its syntax and some API came to be because TS proved that people wanted to use them
Ganesh
Ganesh3mo ago
Was ?. Optional chaining one of them?
Rägnar O'ock
Rägnar O'ock3mo ago
possibly TS usually implements new stuff via polyfills and compilation magic before they land in the browsers and it plays a huge role into the demonstration stages (stage 2 and 3) of proposals
Rägnar O'ock
Rägnar O'ock3mo ago
here's a cool documentary on the history of TS that you can check out fi you want to get a better idea of how it came to be what it is today : https://youtu.be/U6s2pdxebSo?si=52idqEcmWI5kWz2U
OfferZen Origins
YouTube
TypeScript Origins: The Documentary
TypeScript Origins: The Documentary is brought to you by OfferZen - the community-first developer jobs platform. The documentary features core contributors and community members like Anders Hejlsberg, Steve Lucco, Luke Hoban, Daniel Rosenwasser, Ryan Cavanaugh, Amanda Silver, Matt Pocock, Josh Goldberg & many more! It also covers adoption stori...
ἔρως
ἔρως3mo ago
i've found //@ts-check to be extremely useful for even small things it helps me to catch some dumb mistakes i have to admit: the error messages can be absolutely useless i had to google one or 2, and even then i didn't get an answer i had to figure it out on my own
Rägnar O'ock
Rägnar O'ock3mo ago
yeah, ts's error messages are often a bit criptic
ἔρως
ἔρως3mo ago
i found it gives the most cryptic ones when i do a logic error in a condition
Ganesh
Ganesh3mo ago
Is ts-check a js doc thing or ide thing
Rägnar O'ock
Rägnar O'ock3mo ago
it's a ts thing basically a magic comment you can put into your JS files to have the typescript compiler check them as if they were typescript, it only works if you have typescript enabled it's kinda like 'use strict'; in JS
ἔρως
ἔρως3mo ago
it works great in vscode, out of the box
Ganesh
Ganesh3mo ago
What do you mean by typescript enabled?
ἔρως
ἔρως3mo ago
do you use vscode?
Ganesh
Ganesh3mo ago
Yeah. I know it has typescript intelisense baked in
ἔρως
ἔρως3mo ago
yup, you just add that comment and you're done
Ganesh
Ganesh3mo ago
Is that what Ragnar means? You ide should have typescript enabled?
ἔρως
ἔρως3mo ago
it should have a typescript lsp, so it can do ide things
Ganesh
Ganesh3mo ago
Gotcha gotcha
Rägnar O'ock
Rägnar O'ock3mo ago
I mean that you need something to run the typescript compiler or language server for you, usually it'll be your code editor running the language server, but it can also be your build script or a git hook running the typescript compiler
Ganesh
Ganesh3mo ago
So you meant something like this use strict will tell the javascript runtime to run the js file in strict mode. In a similar way @ts-check would tell the lsp, compiler or tool to check for type errors in this js file?
Rägnar O'ock
Rägnar O'ock3mo ago
basically yes it's a bit more complex than that, but that's the idea
Ganesh
Ganesh3mo ago
Gotcha
ἔρως
ἔρως3mo ago
'use strict' can also be used by the lsp
Ganesh
Ganesh3mo ago
Ah yeah since that'll tell to check for strict mode errors for normal js
ἔρως
ἔρως3mo ago
yup
Faker
FakerOP3mo ago
by the way is there any resource suggested to learn typescript please
ἔρως
ἔρως3mo ago
that's wildly out of scope for this post you should make your own post
Faker
FakerOP3mo ago
yep will make another one

Did you find this page helpful?