TypeScriptPresentation



TypeScriptPresentation

0 0


TypeScriptPresentation


On Github codeBelt / TypeScriptPresentation

TypeScript

Just Awesome!

6 things a JavaScript developer needs to know.

1. How to create a Class:

2. The Class always need a constructor:

class Example {

    classProperty = null;

    constructor() {

    }

}

3. Don’t use the function key word to create a function.

class Example {

    classProperty = null;

    constructor() {

    }

    getData() {

    }

}

4. How to create a Class with a namespace.

module myNamespace {

    export class Example {

        classProperty = null;

        constructor() {

        }

    }

}

5. How to extend a Class.

///<reference path='folder/path/BaseClass.ts'/>

module myNamespace {

    import BaseClass = anotherNamespace.BaseClass;

    export class Example extends BaseClass {

        classProperty = null;

        constructor() {

        }

    }

}

6. How to compile. GruntJS.

grunt typescript
typescript: {
    main: {
        src: ['<%= DEVELOPMENT_PATH %>' + 'scripts/TestApp.ts'],
        dest: '<%= DEVELOPMENT_PATH %>' + 'scripts/_compiled/app.js',
        options: {
            target: 'es3',
            base_path: '',
            sourcemap: false,
            declaration: false,
            nolib: false,
            comments: false
        }
    }
}

TypeScript Cons

Needs to be compiled.

Need to create Ambient Class Declarations to use 3rd party js libraries like jQuery, Handlebars, etc

How to create an Ambient Class Declarations

declare var Handlebars:any

TypeScript Pros

  • IDE support (Web/PhpStorm, Sublime, Visual Studio)
  • Easy way to create, extend classes and use interfaces.
  • Produces Source Maps
  • Produces single, multiple or AMD files.
  • Supports type annotations or no type annotations.
  • Supports namespace.
  • Supports default parameters.
  • Compiler watches TS files and produces errors right away if changes affects any other code with in the application.
  • Only compiles classes that are referenced in your code.
  • Reuse classes between projects.

TypeScript Propagation to the Nerdery

Don’t use Type annotations.

Create a TypeScript boilerplate: TypeScript boilerplate

StructureTS a TypeScript framework.

Write a series of tutorials on how to build a Single Page Website App with TypeScript and StructureTS: Demo

QUESTIONS?