Type script:
//union type
let course: string | number = 'Complete guide';
course = 1234;
//type alias
type Person = {
name: string,
age: number;
}
let person: Person;
//generics
function insertAtBeginning(origArray: any[],value: any){
const newArray = [value,...origArray];
return newArray;
}
const demoArray = [1,2,3];
const upadtedArray = insertAtBeginning(demoArray,-1);
upadtedArray[0].split('');
//to
function insertAtBeginning2<T>(origArray: T[],value: T){
const newArray = [value,...origArray];
return newArray;
}
const demoArray2 = [1,2,3];
const upadtedArray2 = insertAtBeginning2(demoArray,-1);
upadtedArray2[0].split(''); //error detected
let idStr: string = "2";
const id = +idStr;
console.log(id*8);
this.isAuthenticated = !user : false : true;
equals
this.isAuthenticated = !!user;
No comments:
Post a Comment