Contents tagged with TypeScript

  • TypeScript class creation

    Hello everybody,

    today I want to document some demos for class declaration in Angular 2. 

    So, let's say you have following class declared:

    Snippet

    import { Component, Injectable } from '@angular/core'

    import { Http, Response } from '@angular/http'

    @Component({

    })

    export class Config {

        public apiKey: string = 'xxxxxyy117c24d8b9085187163f5d241';

        public url: string = 'https://public-api.blablacar.com/api/v2/trips?key=';

        constructor(private http: Http) {

        }

        getReqUrl(): string{

            return this.url + this.apiKey;

        }

    }

    Then the way to create it is the following:

    Snippet

    findTrips()

    {

        let conf = new Config();

        let url: string  … more

  • Saving of typing in TypeScript

    Hello everybody,

    today I want to show two ways of declaring properties in TypeScript.

    Take a look at the following TS code:

    class Animal {

        name: string;

        constructor(name: string) {

            this.name = name;

        }

    }

    Here we declared class Animal, with public property name, and we initialized it in construction. But in TS there is another way of shortcutting this way:

    class Animal {

        constructor(public  name: string) {

            this.name = name;

        }

    }

    With TypeScript you can not only pass members for initialization, but also to declare paramethers of constructor as members of class and also configure access modifiers. more

  • TypeScript notes

    Hello everybody,

    today I want to make some notes of type script, or if to spell it correctly TypeScript.

    So, few words about TS.

    File extensions for TypeScript is .ts. 

    TypeScript is superset of javascript which means that TypeScript understands javscript code. Also for execution TypeScript gots trasplied to javascript. 

    What means transpilation? If to take analogy from C#, it looks like this:

    wonderfulProgram.cs -> C# compiler -> wonderfulProgram.dll 

    Now let compare it with TypeScript:

    wonderfulProgram.ts -> TypeScript compiler ->  wonderfulProgram.js

    Another important part of TypeScript is strong typing:

    JavaScript

    TypeScript

    var x;

    x = 67;

    x='some string'

    x = … more