└── Code ├── main.js └── main.ts /Code/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __extends = (this && this.__extends) || (function () { 3 | var extendStatics = function (d, b) { 4 | extendStatics = Object.setPrototypeOf || 5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 7 | return extendStatics(d, b); 8 | } 9 | return function (d, b) { 10 | extendStatics(d, b); 11 | function __() { this.constructor = d; } 12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 13 | }; 14 | })(); 15 | exports.__esModule = true; 16 | var message = 'Welcome back!'; 17 | console.log(message); 18 | // Variable Declaration 19 | var x = 10; 20 | var y = 20; 21 | var sum; 22 | var title = 'Codevolution'; 23 | // Basic Variable Types 24 | var isBeginner = true; 25 | var total = 0; 26 | var name = 'Vishwas'; 27 | var sentence = "My name is " + name + "\nI am a beginner in TypeScript"; 28 | console.log(sentence); 29 | // Sub types 30 | var n = null; 31 | var u = undefined; 32 | var isNew = null; 33 | var myName = undefined; 34 | // Array type 35 | var list1 = [1, 2, 3]; 36 | var list2 = [1, 2, 3]; 37 | // Tuple type 38 | var person1 = ['Chris', 22]; 39 | // Enum type 40 | var Color; 41 | (function (Color) { 42 | Color[Color["Red"] = 0] = "Red"; 43 | Color[Color["Green"] = 1] = "Green"; 44 | Color[Color["Blue"] = 2] = "Blue"; 45 | })(Color || (Color = {})); 46 | var c = Color.Green; 47 | console.log(c); 48 | // Any type 49 | var randomValue = 10; 50 | randomValue = true; 51 | randomValue = 'Vishwas'; 52 | // Unknown type 53 | var myVariable = 10; 54 | console.log(myVariable.name.firstName); 55 | myVariable(); 56 | myVariable.toUpperCase(); 57 | // Type inference 58 | var a; 59 | a = 10; 60 | a = true; 61 | var b = 10; 62 | // Union Types 63 | var multiType; 64 | multiType = 20; 65 | multiType = true; 66 | var anyType; 67 | anyType = 20; 68 | anyType = true; 69 | // Functions 70 | function add(num1, num2) { 71 | if (num2 === void 0) { num2 = 10; } 72 | if (num2) 73 | return num1 + num2; 74 | else 75 | return num1; 76 | } 77 | add(5, 10); 78 | add(5); 79 | function fullName(person) { 80 | console.log(person.firstName + ' ' + person.lastName); 81 | } 82 | var p = { 83 | firstName: 'Bruce' 84 | }; 85 | fullName(p); 86 | // Classes 87 | var Employee = /** @class */ (function () { 88 | function Employee(name) { 89 | this.employeeName = name; 90 | } 91 | Employee.prototype.greet = function () { 92 | console.log('Good morning ' + this.employeeName); 93 | }; 94 | return Employee; 95 | }()); 96 | var emp1 = new Employee('Vishwas'); 97 | console.log(emp1.employeeName); 98 | emp1.greet(); 99 | var Manager = /** @class */ (function (_super) { 100 | __extends(Manager, _super); 101 | function Manager(managerName) { 102 | return _super.call(this, managerName) || this; 103 | } 104 | Manager.prototype.delegateWork = function () { 105 | console.log('Manager delgating tasks' + this.employeeName); 106 | }; 107 | return Manager; 108 | }(Employee)); 109 | var m1 = new Manager('Bruce'); 110 | m1.delegateWork(); 111 | m1.greet(); 112 | console.log(m1.employeeName); 113 | -------------------------------------------------------------------------------- /Code/main.ts: -------------------------------------------------------------------------------- 1 | export {}; 2 | let message = 'Welcome back!'; 3 | console.log(message); 4 | 5 | // Variable Declaration 6 | let x = 10; 7 | const y = 20; 8 | 9 | let sum; 10 | const title = 'Codevolution'; 11 | 12 | // Basic Variable Types 13 | let isBeginner: boolean = true; 14 | let total: number = 0; 15 | let name: string = 'Vishwas'; 16 | 17 | let sentence: string = `My name is ${name} 18 | I am a beginner in TypeScript`; 19 | 20 | console.log(sentence); 21 | 22 | // Sub types 23 | let n: null = null; 24 | let u: undefined = undefined; 25 | 26 | let isNew: boolean = null; 27 | let myName: string = undefined; 28 | 29 | // Array type 30 | 31 | let list1: number[] = [1, 2, 3]; 32 | let list2: Array = [1, 2, 3]; 33 | 34 | 35 | // Tuple type 36 | 37 | let person1: [string, number] = ['Chris', 22]; 38 | 39 | // Enum type 40 | enum Color {Red, Green, Blue} 41 | let c: Color = Color.Green; 42 | console.log(c); 43 | 44 | // Any type 45 | let randomValue: any = 10; 46 | randomValue = true; 47 | randomValue = 'Vishwas'; 48 | 49 | // Unknown type 50 | let myVariable: any = 10; 51 | console.log(myVariable.name.firstName); 52 | myVariable(); 53 | myVariable.toUpperCase(); 54 | 55 | // Type inference 56 | let a; 57 | a = 10; 58 | a = true; 59 | 60 | let b = 10; 61 | 62 | // Union Types 63 | let multiType: number | boolean; 64 | multiType = 20; 65 | multiType = true; 66 | 67 | let anyType: any; 68 | anyType = 20; 69 | anyType = true; 70 | 71 | // Functions 72 | 73 | function add(num1: number, num2: number = 10): number { 74 | if (num2) 75 | return num1 + num2; 76 | else 77 | return num1; 78 | } 79 | 80 | add(5, 10); 81 | add(5); 82 | 83 | // Interfaces 84 | 85 | interface Person { 86 | firstName: string; 87 | lastName?: string; 88 | } 89 | 90 | function fullName(person: Person) { 91 | console.log(person.firstName + ' ' + person.lastName); 92 | } 93 | 94 | let p = { 95 | firstName: 'Bruce' 96 | }; 97 | fullName(p); 98 | 99 | // Classes 100 | 101 | class Employee { 102 | employeeName: string; 103 | 104 | constructor(name: string) { 105 | this.employeeName = name; 106 | } 107 | 108 | greet() { 109 | console.log('Good morning ' + this.employeeName); 110 | } 111 | } 112 | 113 | let emp1 = new Employee('Vishwas'); 114 | console.log(emp1.employeeName); 115 | emp1.greet(); 116 | 117 | class Manager extends Employee{ 118 | constructor(managerName: string) { 119 | super(managerName); 120 | } 121 | delegateWork() { 122 | console.log('Manager delgating tasks' + this.employeeName); 123 | } 124 | } 125 | 126 | let m1 = new Manager('Bruce'); 127 | m1.delegateWork(); 128 | m1.greet(); 129 | console.log(m1.employeeName); --------------------------------------------------------------------------------