Skip to content

Instantly share code, notes, and snippets.

View mredem96's full-sized avatar

Hojiakbar Karimov mredem96

View GitHub Profile
@mredem96
mredem96 / .tsx
Created February 11, 2019 17:00
Statefull components
import * as React from 'react';
interface IStateComponent{
time:Date();
}
interface IPropComponent{
name:string;
}
@mredem96
mredem96 / .ts
Last active February 11, 2019 13:57
enums
//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";
@mredem96
mredem96 / .ts
Created February 11, 2019 12:50
// 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;
@mredem96
mredem96 / .ts
Last active February 11, 2019 12:31
Shape
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 February 11, 2019 12:03
We know that it actually returns HTMLInputElement or undefined
let input=document.querySelector('input#form_age_field') as HTMLInputElement
@mredem96
mredem96 / gist:f53e914e3bd94204e123558d17ee9fa0
Created February 11, 2019 11:57
Rather than type system guess which type this variable should be we can provide type for a variable
let age:number=22 // ":" this is called type annotation
@mredem96
mredem96 / gist:bb1a5ac3712d7170dc3537b04009c66e
Created February 11, 2019 11:49
TypeScript implicit types
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