Friday 28 December 2012

TypeScript basics

Playground

Nice playground if you want to try anything without installing typescript on you PC.
http://www.typescriptlang.org/Playground/

Definition files

I have found definition source that is updated on regular bases: https://github.com/borisyankov/DefinitelyTyped

Declaring variables

Example of declaring jQuery without definition file:

declare var $: any;
declare var $;

What it does?
This will tell TypeScript that definition $ is defined and is of any type. Both statements are valid.


Using variables that already exists

Lets have script that is defined in one js file.
Script contains only definition variables.

var settings = {"defaultUserName""Unkown","timeout": 1200}
Now lets take the definition and use it in our ts file.

// declare variable that already exists. Leave this on top of the page
declare var settings;

What it does?
This will tell TypeScript that the variable has been already defined and is OK to use it.








No comments:

Post a Comment