Created
August 17, 2019 17:49
-
-
Save yogain123/482d936e879607349cdff71a629bcb30 to your computer and use it in GitHub Desktop.
TypeScript
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
hola |
Author
yogain123
commented
Nov 1, 2019
•
extra
type Choise = "A" | "B" | "C";
let p : Choise = "A"
type testType = keyof {id: "test", age: 2} ; // ==> testType : id | age
let t: testType = "age"
interface MyInterface {
name: string;
}
interface MyInterface {
age: number;
}
let box: MyInterface = { // box will be of type ==> {name:string, age: number}
name:"yogendra",
age:34
}
multiple inheritance
multiple inheritance is not supported in TS, but it is done using interface
interface Person {
pow: (a: number)=>number
}
interface Vehicle {
pow: (a: number)=>number
}
class Body1 implements Person, Vehicle{
personName="done";
pow(a:number): number{
return a*a;
}
}
class Body2 implements Person, Vehicle{
personName="done";
pow(a:number): number{
return a*a*a;
}
}
console.log(new Body1().pow(2)); //4
console.log(new Body2().pow(2)); //8
interface, types, enum syntax
interface Person{
name:string;
age:number
}
type Address = {
pincode:number
country:string
}
type Drink = string | number;
type Boy = [string, boolean];
interface Status{
position:string;
experience: number
}
enum Colors{
b="blue",
g="green"
}
console.log(Colors.b); // blue
function getName(name:string) {
return {
name,
age:25
} as const
}
class Test implements Person, Status, Address{
constructor(public name:string,public age:number, public position:string,public experience:number,
public pincode:number, public country:string){
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment