Typescript

 typescript is a typed superset of javascript

developed by microsoft

object oriented

suport ecma script

we can use data types,classes,interface etc

ide support..code hinting availabale

function overriding problem solve..

node js npm

....promise async await....


npm install -g typescript..to install in window....

error:----

duplicate identifier A

cannot redeclaare block-scoped variable ob..


export{}


what is watch:----

watch for the  file changes and recompile them..


datatypes:---

Array:---down check....

object

union:--1 se jyada type

...class inside function no need of let and func


interface:--

data type define function/object/class property ...

template create...

 



if there will be change auto convert..

tsc app.ts--watch


run file without browser


let conversion:----

bz of diff browser let doesnt support that's why we use...


type declaration:----

let a:string

Array:---

export { }

//let A = Array(1, 2, 3, 4);

let A: number[] = [1, 2, 3, 4, "gaurav"];

//auto type define string and int bz both value are present

console.log(typeof (A));

//A.push();

A[2] = true;

console.log(A[2])//now only number..


object:---------

....default type object...

update property

add new property

define a custom type for object

use any with object...any data willbe accepted



union type:----

let data:string|number....multiple type allow

let data=.........any data value


export { }

interface usertype {

    name: string,

    age: number,

    address: number,

    getdata: () => string,

}

let user: usertype = {

    name: 'peter',

    age: 30,

    address: 20,

    getdata: function () {

        return "hi";

    }

}



//function cals():number...only no will return

function A(a: number, b?: number): number {

    return b ? a + b : a;

}

console.log(A(20, 30));



//class:---

no need to define variable by using let/var

constructor()...syntax...

:void doesnt return anything...






//parent:...extends  inheritance...


module:------

teacher/student..

export default st{

}

import slogin from './student'


object...

access property..


1....export { }

let A: number[] = [1, 2, 3, 4];

A.push()


html+js+ts:---error....

first.js:2 Uncaught ReferenceError: exports is not defined

    at first.js:2

 <script> var exports = {};</script>


function:----

export { }

function f1(a: number, b?: number) {

    return b ? a + b : a;

}

console.log(f1(4, 5));


class:-----

export { }

class A {

    name: string;

    constructor(name) {

        this.name = name;


    }

    getdata() {

        return this.name;

    }

}

let ob = new A('gaurav');

console.log(ob.getdata())


inheritance:--

export { }

class A {

    name: string;

    constructor(name) {

        this.name = name;


    }

    getdata(): string {

        return this.name;

    }

}

class B extends A {

    constructor(name) {

        super('raj');

        console.log(name);

    }

}

let ob = new B('gaurav');

console.log(ob.getdata())


Modules:---

block of code related function class we use to save

if same class in one file so the error will occur

bz function cant be redclare in same file...

export default func1()//samename

{

}

export default funct2()//same name

{

}

import A from './func1'

import A from './func2'


















Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation