TypeScript before JavaScript?

Ben Lovy on October 31, 2018

Shiny objects Am I shooting myself in the foot by learning TypeScript without properly learning JavaScript first? When I started taking... [Read Full]
markdown guide
 

Hmm. We often think of TypeScript as a superset of JavaScript -- as JavaScript with types. But it's just as valid to think of it as a subset of JavaScript. It's JavaScript without the dynamism that skipping a type-checker can give you. There are all kinds of dialects of JavaScript, and only some of them are compatible with the style that TypeScript enforces. So, you might not learn how to think about JavaScript written in different styles!

I'd also be concerned about not really learning what the border between JavaScript and TypeScript is. I work with a lot of early-career Rails developers. Folks who learned Ruby first and then Rails tend to be more successful. Folks who learned the two of them at the same time often really struggle with figuring out what's Ruby and what's Rails. Not knowing what Ruby is "on its own" can really distort their sense of what's possible in Ruby.

I'm not saying that you should put off learning TypeScript! You sound pretty enthusiastic about it. But learning only TypeScript might mean stumbling into some uncanny valleys when you start working with Other People's JavaScript.

 

First off, thanks for the back-and-forth :) I really appreciate it!

That's a great point - I think I've already started running into that fuzzy boundary when I've tried using frameworks. Most of my TypeScript experiments have been pretty vanilla, just learning how the canvas works and things like that, but a few things I tried to do with a TS/React project proved trickier than expected.

It seems like, once again, the fabled missing ingredient is Other People! Funny how that works. Another goal of mine for the near future is a first PR, maybe I should focus on some plain JS codebases to explore.

 

Give yourself some credit -- the canvas can get pretty vicious once animation frames are involved!

Oy - I more meant vanilla as in free of external dependencies but you are not wrong!

 

If you already understand type systems, then typescript is all upside. It'll help you learn the JavaScript and DOM apis quite a bit faster in my experience (7 years of JavaScript, 2 years typescript). I think the only people that should wait in typescript or javscript newbies who don't know type systems either

 

Cool, thanks! I do feel I have a good grasp of type systems from Rust and Haskell, but I will say that TS's structural typing is pretty foreign to me. It's cool seeing different ways of solving that problem.

 

I always try to learn all I need to know to get a job done, then I try to learn the details when I need them.

Do you have a job that needs TypeScript? Learn it.

If you don't have a job that needs TypeScript, then dont learn it.

If nobody tells you if you need it or not, try to figure out the expected complexity of the project and if you comfortable with it, use JS, if you aren't comfortable with the expected complexity, then use TS.

 

That's the thing - I can't tell what does or doesn't need it, and all of my programming experience has been statically and strongly typed. So it sort of feels like every project needs it to me, but that's obviously not the case.

 

If you wanna easy going with coding, you will probably have more luck with TypeScript.

Programming with JavaScript is basically programming with untagged unions only, which feels like a nightmare for many devs.

Since you'll need to bundle up your JavaScript anyway, you can go with the TypeScript tooling, as it won't add much more overhead as the JavaScript tooling.

Easy going sounds good, but not at the expense of actually understanding my code. That does sound like a nightmare, but if that nightmare is the state of the art I'm just prejudiced.

Really appreciate your thoughts! Agreed about the tooling - seems like a six of one sorta deal

 

Here is another question. What if JavaScript was invented after typescript as a subset. What would that world look like?

 

Interesting. Would it still be co considered a subset? I believe (though I'm no math guy) that the set of possible JS programs is larger than the set of possible TS programs.

 

Lots to consider here, I don't think JavaScript would exist at all. Options typing makes typescript equal to JavaScript. Okay what about if JavaScript had a type system that could be enforced. Typescript would become redundant?

I don't think JavaScript would exist at all

I think I agree. Typescript exists to be an enforceable type system for JavaScript, so if such a thing was already built in we wouldn't need something else

You underestimate the developer community 🤣 there is a reason that reinvented of wheels is a common theme. But you have to ask, is the wheel the most optimal shape? So many questions, so much to write about!

 

Sometimes when we start learning Typescript we asume it will behave just like a regular typed language, but it won't, because at the end the browser will be consuming Javascript, so you definitely want to learn how Javascript works and then you will understand better what is actually Typescript doing for you.

 

That makes a lot of sense! It's definitely the most unique type system I've used because of how gradual it is - I can definitely understand the benefit of understanding the underlying systems first before tacking something extra on top.

 

First, you should learn javascript for sure. There is flow by Facebook, that implements static type checker like Typescript; It's a preprocessor. Typescript has more success on types. I do not recommend it (before javascript). There is many many languages transpiles into JS, like Reasonml/OCaml (OCaml is one of my favorites), Elixir (I didn't have tested it but I'm sure it's good), Clojurescript (Has really good interop) etc.

Note that: I'm a JS hater.

 

Thanks for the insight! I'm already familiar with ClojureScript, ReaonML, and OCaml, and have looked at Elixir -- why do you not recommend typescript if you say it's more successful than Flow?

 

(Speaking assuming you know functional programming) It's mostly based on Object-Oriented Programming, and many codebases are written in Javascript and there is a possibility to not understand the JS code because of OOP concepts. Flow helps you to check types without changing the JS code. So it's better to learn JS or any other language because of your similarities.

Gotcha. I'm fairly conceptually comfortable with both paradigms, but you bring up a good point. The OOP I know how to use is not JavaScript's prototypical variety, and that's definitely a potential source of confusion.

 

Typescript is a fantastic language. You're actually learning better practices by starting with Typescript. If I was starting out now I wouldn't learn vanilla JavaScript.

 

Cool! Thanks for the feedback - that was my assumption, at least! Betsy brought up a great point in that there's more valid styles of JS than there are of TS but I still want to learn best practices first

 
 

Don't worry - you can't go wrong with TypeScript. You'll learn a bit more syntax, but you also get better tooling (code completion, error checking etc.) out of the box. I would advise to ALWAYS code in TypeScript instead of JavaScript. If you absolutely can't and you have to use vanilla JS for some reason, all you need to do is to drop the type declarations and change the file ending.

You do NOT waste your time learning TypeScript.

 

Kindred spirits, we are!

TL;DR
I went backwards, and I turned out okay. Also, I did brush up a lot on JavaScript fundamentals during my interviewing process.

 

In more ways than one, though my low brass days are long gone now.

Thanks for sharing your write-up! Thats good to know... I've really been wanting to learn more about Angular but there's only so many hours in a week. I think I only went for react first because I'd used the CLJS analogue - Angular seems a bit more up my alley!

code of conduct - report abuse