Plans

Plans about writings:

Till end of the year:

  1. Finish TypeScript tutorial i started
  2. Go though design patterns
  3. Prepare to use unit testing in production normally with mocking and other stuff
  4. Write as often as i can

Will also write about our Microsoft Hackathon winning project (its opensource and we will continue to write).

Learning TypeScript. Part 1: Any type and primitives

Error: L | Link
Lets start this blog with notes about TypeScript.
Im just learning it myself, so will add some “note type” tips here, with adding my thoughts and some experiments.


So, whats the TypeScript?

From the official website:

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
Any browser. Any host. Any OS. Open Source.

So TypeScript is wrapper over the Javascript language, created by Anders Hejlsberg (The Creator of Delphi and C# (in case someone lived in cave and has no idea about the person)), it adds some OOP abilities to Javascript with static typing, generics etc. We will go though that features later in case i wont be too lazy to write all of this. The code is written in special .ts files that must be compiled to plane javascript and used by any project that works with javascript. For this special compiler was developed; you can use it manually or from the toolset (there are plugins for Visual Studio, Sublime, for example or for testing some tricks you can use website sandbox, the code written there is not sent anywhere, so you can bravely start the Experiments!)

Lets start by checking types that can be used for static typing and special Any type.

Basic Types

There are 3 primitive types in TypeScript: string, number and boolean.

String

As in any other language the representatives of this type are for working with textual data. The data is enclosed in ” or ‘ (as you remember TypeScript is superset of javascript, this means that the same old Javascript code will work in TypeScript). Example:

var name: string = "bob";
name = 'smith';

You also can try this code and see that changing it to name = 1; will give you compile error.

Boolean

Just a true/false strongly typed values:

var isDone: boolean = false;
Number

Numbering type… All the numberings in typescript are floating point numbers, so there is only this type:

var height: number = 6;
Special Any type

Actually all the types can be ‘any’. This is a special type that means that there must be no static check. So that any type can come from dynamically generated content or 3rd party libraries.


var notSure: any = 4;
notSure = "maybe a string instead";
notSure = false; // okay, definitely a boolean

Simple data structures
You sure can work with arrays for example. The array can be strongly typed too:

var list:number[] = [1, 2, 3];

Or the second way, that uses generic types:

var list:Array = [1, 2, 3];

Resources

Wikipedia

Pluralsight

Learn Typescript Official