DEV Community

Cover image for TypeScript Tutorial: A step-by-step guide to learn TypeScript

TypeScript Tutorial: A step-by-step guide to learn TypeScript

Amanda Fawcett on February 17, 2020

Introducing Typescript What is Typescript? Typescript is a typed superset of JavaScript and was created by Microsoft in 2012 ...
Collapse
 
macsikora profile image
Pragmatic Maciej • Edited

Thank you for the article. I want to correct some mistakes. The first which I have spotted, and it is very common is:

Wrong information about OOP

TypesScript is an Object oriented programming language whereas JavaScript is a scripting language.

TS is multi-paradigm language in the same way JS is, JS has also OOP features and at this level TS is in any way more object oriented than JS itself. Statement that TS is OOP and JS is not, would never be correct, as objects exists in the language from beginning. But before ES6 there was no class keyword, and no classical class based OOP syntax, now it's history though.

That said below quote is also outdated information:

Typescript supports object-oriented programming and adds new features to improve upon Javascript’s OOP functionality. Typescript supports the use of classes by using the class keyword

Wrong information about void type

Another mistake is:

Void is a subtype of undefined

Lets check if this is true:

type IsVoidSubTypeUndefined = void extends undefined ? true : false;
// above evaluates to false
Enter fullscreen mode Exit fullscreen mode

It means void is not a subtype of undefined type. undefined is really a unit type in the same way void is, there is no relation between these types.

Mistake about instanceof

This operator can check for custom types not defined by Javascript. Below, we first write a custom type, make an instance of it, and check that it is indeed the right variable.

Its not valid, instanceof is valid JS operator, it works only with objects created by new. Its not any kind of TS feature, saying that it has something with

custom types not defined by Javascript

is incorrect.

Also I very dislike the whole Step 9 as it mixes JS operators which exists in the runtime with TS operators existing only at compilation. In Step 2 you describe some types in some random way, and surprisingly there is no info about Record and Union types which are the basic tool for every TS programmer.

In summary I want to thank you for the effort, but I am very sorry to say in my opinion some information's in the article could be double checked and verified.

Collapse
 
amandaeducative profile image
Amanda Fawcett

Hi Ben! I am pleased to hear that you found the tutorial helpful. I do have a few TS resources in mind that range in difficulty level, depending on your learning goals.

Here is an article on advanced TS: educative.io/blog/advanced-typescr...

An article on using TS & React: educative.io/blog/react-and-typesc...

Another, more extensive beginner's guide to TS: valentinog.com/blog/typescript/

The official documentation and tutorial for TS (these are a bit denser, but can be helpful): typescriptlang.org/v2/docs/home

Here is a helpful learning track specifically for TS developers: educative.io/track/typescript-for-...

My recommendation is to avoid using videos unless you have benefited from them in the past. TS can be tricky to learn, and it requires some exploration & hands-on trial/error to figure out. One great way to learn is to look at other peoples' TS projects and try to replicate them.

Hope that helps!

Collapse
 
sushantrahate profile image
Sushant Rahate

Thank you for great tutorial

Collapse
 
ahmedash95 profile image
Ahmed Ashraf

Thanks for the great article Amanda, can you just edit the code blocks to support highlighting markdownguide.org/extended-syntax/...

Collapse
 
niftycode profile image
Bodo Schönfeld

Thank you for this introduction!

Collapse
 
osde8info profile image
Clive Da

fab thanks

Collapse
 
monfernape profile image
Usman Khalil

It was a helpful guide. Thank you

Collapse