Member-only story

Learning TypeScript 01 — Basic types

Quique Fdez. Guerra
4 min readFeb 2, 2018

--

In TypeScript we have some basic types that we have on JavaScript too and some more. The cool thing here is that you are checking the types on compilation time before executing your code.

Also if you’re using a modern IDE or code editor, you will have information of the types meanwhile you’re writing your code.

How to declare a variable with a particular type

If you want to specify the type of a variable you will write something like this:

var developer: type;

or

var developer: type = value;

If you are working in a function:

function developing(developer: type): type {...}

Boolean

The basic of the basics, that is how you can declare a boolean variable:

const isDeveloper: boolean = true;

Numbers

TypeScript can understand some different numbers, but all of them are the same type:

const binary: number = 0b1010;
const integer: number = 5;
const

--

--

Quique Fdez. Guerra
Quique Fdez. Guerra

Written by Quique Fdez. Guerra

Director of Engineering at @PlainConcepts Romania Frontend Developer Lazy @Github contributor Happy @Helpdev_ founder Web @GoogleDevExpert

No responses yet