DEV Community

Cover image for TypeScript in a Weekend: A Crash Course

TypeScript in a Weekend: A Crash Course

Shane Lonergan on May 17, 2020

I am in the midst of searching for my first job as a developer, and I recently interviewed at a company for which I thought I would be a great fit....
Collapse
 
iwi4a_24 profile image
Ivelin • Edited

Excellent article, really enjoyed reading it. 🙌 To add something in, it might be worth mentioning that interface properties could be declared as optional by using ? at the end of the name, I find it as quite useful feature. ⭐ Again, thanks for sharing! ⭐

Collapse
 
shane__lonergan profile image
Shane Lonergan

Ah yes, that would be great to include! Thank you for the suggestion, and for the kind words. I am glad you enjoyed it!

Collapse
 
ouailsalem profile image
Ouail

Thank you so much ♡
Just a question , what's the difference between array and enum?

Collapse
 
krishnakakade profile image
krishna kakade

The main difference is that an array is a value and an enum is a type. And One main difference we can say that an array is a collection of other values (that is it contains other values, you can iterate through them or access individual ones by index), whereas an enum value is simply one atomic value

Collapse
 
peacefulseeker profile image
Alexey Vorobyov

Won't TypeScript complain about Hip-Hop enum which is not wrapped into quotes?🤔

Collapse
 
shane__lonergan profile image
Shane Lonergan

Yes, it will! I should have omitted the hyphen 🤦‍♂️. Thanks for the catch!

Collapse
 
fasani profile image
Michael Fasani

Hey @shane__lonergan

The very first code example contains TypeScript.

function printNameAndAge(person: string, ageInYears: number): void {

I am guessing this should be regular JavaScript.

Collapse
 
lawrancemichaelite profile image
LawranceMichaelite

Do I need to know JS before learning TS ?

Collapse
 
jamesthomson profile image
James Thomson

Yes, TypeScript isn't a replacement for JavaScript. Its intent is to enhance JS by making it typed, but for the most part you'll still be writing JS.

Collapse
 
lawrancemichaelite profile image
LawranceMichaelite

Okay! I got it.. Thanks... Have A Great Day

Collapse
 
a1tem profile image
Artem Petrusenko

Thank you for the introduction !

Collapse
 
thisdotmedia_staff profile image
This Dot Media

This is great! Very well-written 😄

Collapse
 
vetras profile image
vetras

Typo "sumSongs" on interface, "numSongs" on object

You're not using the compiler Shane .... !!
Congratz, good article.

Collapse
 
shane__lonergan profile image
Shane Lonergan

Thank you for your kind words, and for letting me know about the typo! And yes, I figured I would save the compiler for its own post.

Collapse
 
krishnakakade profile image
krishna kakade

Thanks shane good article

Collapse
 
evankapantais profile image
Evan Kapantais

Good intro, but you have many typos in your code snippets.

Collapse
 
aybee5 profile image
Ibrahim Abdullahi Aliyu

Thank you very much for this, can you please shade more light on enums?

Collapse
 
jestevezrod profile image
Jesus Estevez

Interesting article! Thank you

Collapse
 
enriqueedelberto profile image
Edelberto Enrique Reyes

Thanks for sharing.

Collapse
 
ahmed_elgaidi profile image
Ahmed Elgaidi

Amazing !
keep going, bro

Collapse
 
pwob profile image
Patrick Buitre

Hi is this a typo?

type FlexibleNumber = number | string
let luckyNumber: flexibleNumber = 13

Collapse
 
meatboy profile image
Meat Boy

What the difference between types and interfaces? I thought before the interface is for class and type for the object.

Collapse
 
lufradenogueira profile image
Luísa Nogueira

I liked the article! It is simple and has all the basic relevant facts :)