TypeScript essentials
getting started with this extension of JavaScript
The essence of TypeScript
We use TypeScript to validate variables by assigning each variable in TypeScript a type:
Breaking that down:
the
yearRound
variable has a primitive type ofboolean
thus,
yearRound
can only be eithertrue
orfalse
the
cost
has a type of anumber
(JavaScript has no integers or floats; all numeric data are just
number
s)thus,
cost
cannot have symbols other than digits and legal operators
the
destination
has the type of an object{}
this object, in turn, contains a property called
name
the
name
has a type ofstring
Abstracting that further:
type
can take on any of the following (with a few more others):string
number
boolean
Date
unknown
void
never
the
type
can also be arrays of each of the above, e.g.string[]
number[]
as shown in the earlier top snippet, the
type
can also be an objectthe properties in that object would also get their own
type
s
Last updated