Skip to content

Instantly share code, notes, and snippets.

@ekam230
Created February 13, 2022 08:47
Show Gist options
  • Save ekam230/a7299119b941494132afafa877a71be6 to your computer and use it in GitHub Desktop.
Save ekam230/a7299119b941494132afafa877a71be6 to your computer and use it in GitHub Desktop.
Typescript learn
//JS
typeof 42 //number
typeof 'str' //string
typeof true //boolean
typeof [] //object
typeof {} //object
typeof null //object
typeof undefined //undefined
typeof Symbol(); //symbol
//
let isComleted:boolean =false;
const decimal:number = 6; //number
const name1: string = 'Yauhen';
const sentence: string = `Hello ${name1}`
const u: undefined = undefined;
const n: null = null;
//function void with no return
const greetUserJs = (): void =>{
alert('dasdasd');
}
//Array type
let list:number[] = [1,2,3]
let list2:Array<number> = [1,2,3]
//tuple
let x: [string,number]
x = ["hello",10]
//one line
let y:[string,number] = ["good",42]
//ANY_TYPE
let y1:[any,any] = ["goodbuy",42]
let z1: Array<any> = [10,"dasdsa"]
//any type for string
let notSure: any=false;
//Enum
enum Directions{
Up,
Down,
Left,
Right
}
Directions.Up; //0
Directions.Down //1
//enum custom index
enum Directions2{
Up=2,
Down=4,
Left,
Right
}
Directions2.Up; //2
Directions2.Down //4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment