Skip to content

Instantly share code, notes, and snippets.

Hojiakbar Karimov mredem96

View GitHub Profile
@mredem96
mredem96 / .tsx
Created Feb 11, 2019
Statefull components
View .tsx
import * as React from 'react';
interface IStateComponent{
time:Date();
}
interface IPropComponent{
name:string;
}
View .ts
//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";
View .ts
// 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;
View .ts
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'
@mredem96
mredem96 / gist:7b3ce8b5f2266eb60346add0eaa264aa
Created Feb 11, 2019
We know that it actually returns HTMLInputElement or undefined
View gist:7b3ce8b5f2266eb60346add0eaa264aa
let input=document.querySelector('input#form_age_field') as HTMLInputElement
@mredem96
mredem96 / gist:f53e914e3bd94204e123558d17ee9fa0
Created Feb 11, 2019
Rather than type system guess which type this variable should be we can provide type for a variable
View gist:f53e914e3bd94204e123558d17ee9fa0
let age:number=22 // ":" this is called type annotation
View gist:bb1a5ac3712d7170dc3537b04009c66e
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
You can’t perform that action at this time.