TypeScript and JQuery example

This is an example of using TypeScript and JQuery.

Steps:

1] Install TypeScript from here: http://www.typescriptlang.org/

2] Create typescript file hello.ts:

see typescript file

3] Get a JQuery TypeScript definition
file jquery.d.ts, for example here: https://github.com/borisyankov/DefinitelyTyped#readme

4] Compile to javascript
using command tsc:

tsc hello.tsc

5] Inspect javascript file
A javascript file hello.js is generated

see javascript file

6] Create html page
Now we can use the javascript in a html page:

see html file

7] Result
Result should be: ‘hallo bert’

Complete code:

Advertisements

3 thoughts on “TypeScript and JQuery example

  1. Nice example, but why use $(document).ready ?
    jquery replaced that function with $(function( ){/***/});
    Anyways, good example, thank you for taking time to write this code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s