This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
interface IStateComponent{ | |
time:Date(); | |
} | |
interface IPropComponent{ | |
name:string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this is TypeScript declaration | |
enum Suit { | |
Club, Diamond, Heart, Spade | |
} | |
// in JavaScript like this | |
var Suit; | |
(function(Suit){ | |
Suit[Suit["Club"]=0]="Club"; | |
Suit[Suit["Diamond"]=1]="Diamond"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// It is the worht mentioning that Putting I+your interface name is best practice | |
// we define our Date shape object | |
interface IDate { | |
year:number; | |
month:number; | |
day:number; | |
} | |
interface IPerson{ | |
name:string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function registerUser(user:{name:string,age:number,gender:string}){ | |
.... /// some function implementation | |
} | |
// let's define some shapes | |
//ok | |
let person1={ | |
name:'Hojiakbar', | |
age:22, | |
gender:'male' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let input=document.querySelector('input#form_age_field') as HTMLInputElement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let age:number=22 // ":" this is called type annotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let age=22 // TypeScript smart enough to know this is number | |
age='22' // This is not ok string type is not assignible to a type number |