├── Workshop ├── .gitignore ├── dist │ ├── bundle.js │ ├── index.html │ └── css │ │ └── style.css ├── src │ ├── views │ │ ├── post.ts │ │ └── user.ts │ ├── types │ │ ├── routerTypes.ts │ │ ├── postTypes.ts │ │ ├── commonTypes.ts │ │ └── userTypes.ts │ ├── constants.ts │ ├── router.ts │ ├── utils │ │ ├── httpUtil.ts │ │ └── htmlUtil.ts │ ├── services │ │ ├── postService.ts │ │ ├── userService.ts │ │ └── httpService.ts │ └── index.ts ├── tsconfig.json ├── package.json └── webpack.config.js ├── README.md ├── Namespaces-and-Modules ├── skeleton-demo │ ├── src │ │ └── index.ts │ ├── dist │ │ ├── bundle.js │ │ └── index.html │ ├── tsconfig.json │ ├── package.json │ └── webpack.config.js ├── modules-demo │ ├── dist │ │ ├── interfaces │ │ │ └── Person.js │ │ ├── utils │ │ │ ├── string-utils.js │ │ │ └── person-util.js │ │ └── index.js │ ├── src │ │ ├── utils │ │ │ ├── string-utils.ts │ │ │ └── person-util.ts │ │ ├── interfaces │ │ │ └── Person.ts │ │ └── index.ts │ ├── package.json │ ├── package-lock.json │ └── tsconfig.json └── namespaces-demo │ ├── Animal.ts │ ├── index.ts │ └── tsconfig.json ├── Exam-Prep ├── 01.Calculator │ ├── tsconfig.json │ ├── dist │ │ └── index.js │ └── src │ │ └── index.ts ├── 02.LowestPricesInCitites │ ├── tsconfig.json │ ├── dist │ │ └── index.js │ └── src │ │ └── index.ts └── 03.ClotheMagazine │ ├── tsconfig.json │ ├── src │ ├── Cloth.ts │ ├── index.ts │ └── Magazine.ts │ └── dist │ ├── Cloth.js │ ├── Magazine.js │ └── index.js ├── Interfaces-and-Generics ├── tsconfig.json ├── dist │ ├── interfaces-demo │ │ ├── app-fetch-demo.js │ │ ├── app-types-demo.js │ │ └── app-interfaces-demo.js │ └── app-generics-demo.js └── src │ ├── interfaces-demo │ ├── app-fetch-demo.ts │ ├── app-types-demo.ts │ └── app-interfaces-demo.ts │ └── app-generics-demo.ts ├── Intro-TypeScript ├── tsconfig.json ├── dist │ ├── goodPractices.js.map │ ├── goodPractices.js │ ├── app.js.map │ └── app.js └── src │ ├── goodPractices.ts │ └── app.ts ├── TypeScript-OOP ├── tsconfig.json ├── dist │ ├── app.js.map │ └── app.js └── src │ └── app.ts └── Decorators ├── tsconfig.json ├── app-params-demo.ts ├── app-factory-demo.ts ├── app-field-demo.js ├── app-field-demo.ts ├── app-accessor-demo.ts ├── app-method-demo.ts ├── app-class-demo.ts ├── app-params-demo.js ├── app-accessor-demo.js ├── app-factory-demo.js ├── app-class-demo.js └── app-method-demo.js /Workshop/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Here we will upload the demos from TypeScript course in Softuni. 2 | -------------------------------------------------------------------------------- /Workshop/dist/bundle.js: -------------------------------------------------------------------------------- 1 | (()=>{"use strict";console.log("Hello, TypeScript!")})(); -------------------------------------------------------------------------------- /Namespaces-and-Modules/skeleton-demo/src/index.ts: -------------------------------------------------------------------------------- 1 | console.log("Hello, TypeScript!"); 2 | -------------------------------------------------------------------------------- /Workshop/src/views/post.ts: -------------------------------------------------------------------------------- 1 | export const postPage = `
Hello, from POST page!
`; 2 | -------------------------------------------------------------------------------- /Workshop/src/views/user.ts: -------------------------------------------------------------------------------- 1 | export const userPage = `
Hello, from USER page!
`; 2 | -------------------------------------------------------------------------------- /Workshop/src/types/routerTypes.ts: -------------------------------------------------------------------------------- 1 | export type RouterMap = { 2 | [key: string]: string; 3 | }; 4 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/skeleton-demo/dist/bundle.js: -------------------------------------------------------------------------------- 1 | (()=>{"use strict";console.log("Hello, TypeScript!")})(); -------------------------------------------------------------------------------- /Workshop/src/constants.ts: -------------------------------------------------------------------------------- 1 | export const CONFIG = { 2 | BASE_URL: "https://jsonplaceholder.typicode.com", 3 | }; 4 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/dist/interfaces/Person.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | -------------------------------------------------------------------------------- /Workshop/src/types/postTypes.ts: -------------------------------------------------------------------------------- 1 | export type Post = { 2 | userId: number; 3 | id: number; 4 | title: string; 5 | body: string; 6 | }; 7 | -------------------------------------------------------------------------------- /Exam-Prep/01.Calculator/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./dist", 4 | "rootDir": "./src", 5 | "target": "ES2020" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Exam-Prep/02.LowestPricesInCitites/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./dist", 4 | "rootDir": "./src", 5 | "target": "ES2020" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Workshop/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | // "module": "es6", 5 | // "strict": true, 6 | "sourceMap": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/src/utils/string-utils.ts: -------------------------------------------------------------------------------- 1 | export const capitalizeFirstLetter = (str: string) => { 2 | return str.charAt(0).toUpperCase() + str.slice(1); 3 | }; 4 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/skeleton-demo/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "es6", 5 | "strict": true, 6 | "sourceMap": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Exam-Prep/03.ClotheMagazine/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "module": "CommonJS", 5 | "outDir": "./dist", 6 | "rootDir": "./src" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/src/interfaces/Person.ts: -------------------------------------------------------------------------------- 1 | export interface PersonDetails { 2 | name: string; 3 | age: number; 4 | } 5 | 6 | export interface PersonDetailsWithoutAge { 7 | name: string; 8 | } 9 | -------------------------------------------------------------------------------- /Interfaces-and-Generics/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2020", 4 | "module": "commonjs", 5 | "rootDir": "./src", 6 | "outDir": "./dist", 7 | "strict": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Intro-TypeScript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "module": "commonjs", 5 | "rootDir": "./src", 6 | "outDir": "./dist", 7 | "strict": true, 8 | "sourceMap": true // debug 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /TypeScript-OOP/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "module": "commonjs", 5 | "rootDir": "./src", 6 | "outDir": "./dist", 7 | "strict": true, 8 | "sourceMap": true // debug 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Workshop/src/router.ts: -------------------------------------------------------------------------------- 1 | import { RouterMap } from "./types/routerTypes"; 2 | import { postPage } from "./views/post"; 3 | import { userPage } from "./views/user"; 4 | 5 | export const router: RouterMap = { 6 | "/": userPage, 7 | "/post": postPage, 8 | }; 9 | -------------------------------------------------------------------------------- /Intro-TypeScript/dist/goodPractices.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"goodPractices.js","sourceRoot":"","sources":["../src/goodPractices.ts"],"names":[],"mappings":";AAAA,kCAAkC;AAClC,yCAAyC;AACzC,uBAAuB;AACvB,+BAA+B;AAE/B,kFAAkF;AAElF,gEAAgE;AAChE,6CAA6C;AAC7C,KAAK;AAEL,gDAAgD;AAChD,2CAA2C"} -------------------------------------------------------------------------------- /Workshop/src/utils/httpUtil.ts: -------------------------------------------------------------------------------- 1 | export const fetchUtil = (url: string, httpConfig?: RequestInit) => { 2 | return fetch(url, httpConfig) 3 | .then((response) => response.json()) 4 | .then((data: T) => { 5 | console.log(data); 6 | }) 7 | .catch((error) => console.error(error)); 8 | }; 9 | -------------------------------------------------------------------------------- /Decorators/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /** Decorators Stage 2 */ 4 | // "target": "ES5", 5 | // "experimentalDecorators": true, 6 | // "emitDecoratorMetadata": true 7 | 8 | /** Decorators Stage 3 - TypeScript version - 5 */ 9 | "target": "ES2022" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/dist/utils/string-utils.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.capitalizeFirstLetter = void 0; 4 | const capitalizeFirstLetter = (str) => { 5 | return str.charAt(0).toUpperCase() + str.slice(1); 6 | }; 7 | exports.capitalizeFirstLetter = capitalizeFirstLetter; 8 | -------------------------------------------------------------------------------- /Workshop/src/types/commonTypes.ts: -------------------------------------------------------------------------------- 1 | export type Company = { 2 | name: string; 3 | catchPhrase: string; 4 | bs: string; 5 | }; 6 | 7 | export type Geo = { 8 | lat: string; 9 | lng: string; 10 | }; 11 | 12 | export type Address = { 13 | street: string; 14 | suite: string; 15 | city: string; 16 | zipcode: string; 17 | geo: Geo; 18 | }; 19 | -------------------------------------------------------------------------------- /Workshop/src/types/userTypes.ts: -------------------------------------------------------------------------------- 1 | import { Address, Company } from "./commonTypes"; 2 | 3 | export type User = { 4 | id: number; 5 | name: string; 6 | username: string; 7 | email: string; 8 | phone: string; 9 | }; 10 | 11 | export type UserDetails = { 12 | user: User; 13 | address: Address; 14 | website: string; 15 | company: Company; 16 | }; 17 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "modules-demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "type": "commonjs", 7 | "scripts": { 8 | "build": "tsc && node dist/index" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "typescript": "^5.2.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Exam-Prep/03.ClotheMagazine/src/Cloth.ts: -------------------------------------------------------------------------------- 1 | export class Cloth { 2 | color: string; 3 | size: number; 4 | type: string; 5 | 6 | constructor(color: string, size: number, type: string) { 7 | this.color = color; 8 | this.size = size; 9 | this.type = type; 10 | } 11 | 12 | toString(): string { 13 | return `Product: ${this.type} with size ${this.size}, color ${this.color}`; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Workshop/src/services/postService.ts: -------------------------------------------------------------------------------- 1 | import { Post } from "../types/postTypes"; 2 | import { fetchUtil } from "../utils/httpUtil"; 3 | import { HttpService } from "./httpService"; 4 | 5 | export class PostsService extends HttpService { 6 | constructor(baseUrl: string) { 7 | super(`${baseUrl}/posts`); 8 | } 9 | 10 | getUserPosts(userId: number) { 11 | fetchUtil(`${this.apiUrl}?userId=${userId}`); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Exam-Prep/03.ClotheMagazine/dist/Cloth.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.Cloth = void 0; 4 | class Cloth { 5 | constructor(color, size, type) { 6 | this.color = color; 7 | this.size = size; 8 | this.type = type; 9 | } 10 | toString() { 11 | return `Product: ${this.type} with size ${this.size}, color ${this.color}`; 12 | } 13 | } 14 | exports.Cloth = Cloth; 15 | -------------------------------------------------------------------------------- /Intro-TypeScript/src/goodPractices.ts: -------------------------------------------------------------------------------- 1 | // // variable name -> descriptive 2 | // const tableNumbersRows = [1, 2, 3, 4]; 3 | // const isMale = true; 4 | // const hasPermission = false; 5 | 6 | // const arrayOfPerson = [{ name: "Kiro" }, { name: "Pesho" }, { name: "Mariq" }]; 7 | 8 | // const getPersonNamesCollection = (arrayOfPerson): string => { 9 | // return arrayOfPerson.map((p) => p.name); 10 | // }; 11 | 12 | // /** This function calculates angles of ... */ 13 | // const fnZxx = (a, b) => (a * b) % b ^ a; 14 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/skeleton-demo/dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 |

Hello, TypeScript!

11 | 12 |
13 | 14 | 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /Workshop/src/services/userService.ts: -------------------------------------------------------------------------------- 1 | // import { withPosts } from "../decorators/userDecorator"; 2 | import { User } from "../types/userTypes"; 3 | import { HttpService } from "./httpService"; 4 | 5 | export class UsersService extends HttpService { 6 | constructor(baseUrl: string) { 7 | super(`${baseUrl}/users`); 8 | } 9 | 10 | userGetAll() { 11 | // validation 12 | this.getAll(); 13 | } 14 | 15 | getSingleUser(id: number, cb: Function) { 16 | this.getOne(id); 17 | cb(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Workshop/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "skeleton-demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "webpack --mode production", 8 | "dev": "webpack-dev-server --mode development" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "ts-loader": "^9.5.0", 15 | "typescript": "^5.2.2", 16 | "webpack": "^5.89.0", 17 | "webpack-cli": "^5.1.4", 18 | "webpack-dev-server": "^4.15.1" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Interfaces-and-Generics/dist/interfaces-demo/app-fetch-demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const USERS_URL = "https://jsonplaceholder.typicode.com/posts"; 3 | function getUsers() { 4 | fetch(USERS_URL, { method: "GET" }) 5 | .then((res) => { 6 | return res.json(); 7 | }) 8 | .then((data) => { 9 | const postTiles = data.map((post) => { 10 | return post.title; 11 | }); 12 | console.log({ postTiles }); 13 | }) 14 | .catch((err) => console.log(`Error: ${err}`)); 15 | } 16 | getUsers(); 17 | -------------------------------------------------------------------------------- /Intro-TypeScript/dist/goodPractices.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // // variable name -> descriptive 3 | // const tableNumbersRows = [1, 2, 3, 4]; 4 | // const isMale = true; 5 | // const hasPermission = false; 6 | // const arrayOfPerson = [{ name: "Kiro" }, { name: "Pesho" }, { name: "Mariq" }]; 7 | // const getPersonNamesCollection = (arrayOfPerson): string => { 8 | // return arrayOfPerson.map((p) => p.name); 9 | // }; 10 | // /** This function calculates angles of ... */ 11 | // const fnZxx = (a, b) => (a * b) % b ^ a; 12 | //# sourceMappingURL=goodPractices.js.map -------------------------------------------------------------------------------- /Namespaces-and-Modules/skeleton-demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "skeleton-demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "webpack --mode production", 8 | "dev": "webpack-dev-server --mode development" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "ts-loader": "^9.5.0", 15 | "typescript": "^5.2.2", 16 | "webpack": "^5.89.0", 17 | "webpack-cli": "^5.1.4", 18 | "webpack-dev-server": "^4.15.1" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Interfaces-and-Generics/dist/interfaces-demo/app-types-demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | function getMammal() { 3 | const dog = { 4 | name: "Johny", 5 | legsCount: 4, 6 | furColor: "brown", 7 | eat: () => console.log("Dog is eating"), 8 | }; 9 | return dog; 10 | } 11 | // class Dog implements Mammal { 12 | // legsCount: number; 13 | // furColor: string; 14 | // /** 15 | // * 16 | // */ 17 | // constructor() { 18 | // this.legsCount = 4; 19 | // this.furColor = "yellow"; 20 | // } 21 | // } 22 | // const dog1 = new Dog(); 23 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/src/utils/person-util.ts: -------------------------------------------------------------------------------- 1 | import { PersonDetails, PersonDetailsWithoutAge } from "../interfaces/Person"; 2 | import * as stringUtl from "./string-utils"; 3 | 4 | const tranformPersonNameToCapitalLetter = ( 5 | person: PersonDetails | PersonDetailsWithoutAge 6 | ) => { 7 | const { name } = person; 8 | 9 | return { 10 | ...person, 11 | name: stringUtl.capitalizeFirstLetter(name), 12 | }; 13 | }; 14 | 15 | export default function xx123() { 16 | return 10; 17 | } 18 | 19 | export { tranformPersonNameToCapitalLetter as nameCapitalizer }; 20 | -------------------------------------------------------------------------------- /Workshop/dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Workshop 7 | 8 | 9 | 10 |
11 | 15 |
16 |
17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/namespaces-demo/Animal.ts: -------------------------------------------------------------------------------- 1 | namespace AnimalGroup { 2 | export class Animal { 3 | furColor: string; 4 | type: string; 5 | 6 | constructor(furColor: string, numberOfLegs: number, type: string) { 7 | this.furColor = furColor; 8 | this.type = type; 9 | } 10 | 11 | getDetails() { 12 | return `This animal is of type ${this.type} and it has fur in a color of ${this.furColor}`; 13 | } 14 | } 15 | } 16 | 17 | namespace HumanGroup { 18 | export class Human { 19 | constructor() {} 20 | 21 | greetings() { 22 | return `Hi I am a human`; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Interfaces-and-Generics/src/interfaces-demo/app-fetch-demo.ts: -------------------------------------------------------------------------------- 1 | const USERS_URL = "https://jsonplaceholder.typicode.com/posts"; 2 | 3 | // interface Post { 4 | type Post = { 5 | userId: number; 6 | id: number; 7 | title: string; 8 | body: string; 9 | }; 10 | 11 | function getUsers(): void { 12 | fetch(USERS_URL, { method: "GET" }) 13 | .then((res) => { 14 | return res.json(); 15 | }) 16 | .then((data: Post[]) => { 17 | const postTiles = data.map((post) => { 18 | return post.title; 19 | }); 20 | 21 | console.log({ postTiles }); 22 | }) 23 | .catch((err) => console.log(`Error: ${err}`)); 24 | } 25 | 26 | getUsers(); 27 | -------------------------------------------------------------------------------- /Interfaces-and-Generics/dist/interfaces-demo/app-interfaces-demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Can be implemented by a class 3 | class Person { 4 | constructor(firstName, lastName, legsCount, skinColor) { 5 | this.firstName = firstName; 6 | this.lastName = lastName; 7 | this.legsCount = legsCount; 8 | this.skinColor = skinColor; 9 | this.fullName = this.firstName + " " + this.lastName; 10 | } 11 | } 12 | const personGosho = new Person("Gosho", "Kirilov", 2, "zelena"); 13 | // can be used as a type of a variable 14 | const user = { 15 | firstName: "Tsveti", 16 | lastName: "Petrov", 17 | }; 18 | const getName = (param1, param2) => { 19 | return ""; 20 | }; 21 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/src/index.ts: -------------------------------------------------------------------------------- 1 | import { PersonDetails, PersonDetailsWithoutAge } from "./interfaces/Person"; 2 | import * as PersonStuff from "./interfaces/Person"; 3 | import xx123 from "./utils/person-util"; 4 | import { nameCapitalizer } from "./utils/person-util"; 5 | 6 | const person1: PersonDetails = { age: 22, name: "mitko" }; 7 | const person2: PersonDetailsWithoutAge = { name: "mitko2" }; 8 | 9 | const personOneCapitalized = nameCapitalizer(person1); 10 | console.log(person1); 11 | console.log(personOneCapitalized); 12 | 13 | const personTwoCapitalized = nameCapitalizer(person2); 14 | console.log(person2); 15 | console.log(personTwoCapitalized); 16 | 17 | console.log(xx123()); 18 | -------------------------------------------------------------------------------- /Decorators/app-params-demo.ts: -------------------------------------------------------------------------------- 1 | class Example { 2 | @validateParams 3 | someMethod(arg1?: string, arg2?: number) { 4 | console.log(`Recieved params: ${arg1}, ${arg2}`); 5 | } 6 | } 7 | 8 | function validateParams( 9 | target: Function, 10 | context: ClassMethodDecoratorContext 11 | ) { 12 | return function (...args: any) { 13 | for (let i = 0; i < args.length; i++) { 14 | const currentArg = args[i]; 15 | if (currentArg === undefined || currentArg === null) { 16 | throw new Error(`Parameter at index ${i} is invalid!`); 17 | } 18 | 19 | target.apply(this, args); 20 | } 21 | }; 22 | } 23 | 24 | const exampleInstance = new Example(); 25 | exampleInstance.someMethod("Hi", 12); 26 | -------------------------------------------------------------------------------- /Workshop/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | module.exports = { 4 | // devtool: "eval-source-map", 5 | entry: path.resolve(__dirname, "src/index.ts"), // Your entry TypeScript file 6 | module: { 7 | rules: [ 8 | { 9 | test: /\.ts$/, 10 | use: "ts-loader", 11 | include: [path.resolve(__dirname, "src")], 12 | }, 13 | ], 14 | }, 15 | output: { 16 | filename: "bundle.js", 17 | path: path.resolve(__dirname, "dist"), 18 | }, 19 | resolve: { 20 | extensions: [".ts", ".js"], 21 | }, 22 | devServer: { 23 | static: path.resolve(__dirname, "dist"), 24 | port: 3000, 25 | hot: true, 26 | open: true, 27 | compress: true, 28 | }, 29 | }; 30 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/skeleton-demo/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | module.exports = { 4 | // devtool: "eval-source-map", 5 | entry: path.resolve(__dirname, "src/index.ts"), // Your entry TypeScript file 6 | module: { 7 | rules: [ 8 | { 9 | test: /\.ts$/, 10 | use: "ts-loader", 11 | include: [path.resolve(__dirname, "src")], 12 | }, 13 | ], 14 | }, 15 | output: { 16 | filename: "bundle.js", 17 | path: path.resolve(__dirname, "dist"), 18 | }, 19 | resolve: { 20 | extensions: [".ts", ".js"], 21 | }, 22 | devServer: { 23 | static: path.resolve(__dirname, "dist"), 24 | port: 3000, 25 | hot: true, 26 | open: true, 27 | compress: true, 28 | }, 29 | }; 30 | -------------------------------------------------------------------------------- /Decorators/app-factory-demo.ts: -------------------------------------------------------------------------------- 1 | type Task = { 2 | name: string; 3 | level: "low" | "medium" | "complicated"; 4 | }; 5 | 6 | class Employee { 7 | @withTask({ name: "Task1 ", level: "complicated" }) 8 | tasks: Task[] = []; 9 | 10 | @withComplicatedTask() 11 | extraTasks: Task[] = []; 12 | } 13 | 14 | const employee = new Employee(); 15 | console.log(employee); 16 | 17 | function withTask(task: Task) { 18 | return function ( 19 | target: undefined, 20 | context: ClassFieldDecoratorContext 21 | ) { 22 | return function (args: V) { 23 | args.push(task); 24 | return args; 25 | }; 26 | }; 27 | } 28 | 29 | function withComplicatedTask() { 30 | return withTask({ name: "Some Other Task", level: "complicated" }); 31 | } 32 | -------------------------------------------------------------------------------- /Decorators/app-field-demo.js: -------------------------------------------------------------------------------- 1 | // type Task = { 2 | // name: string; 3 | // level: "low" | "medium" | "complicated"; 4 | // }; 5 | // class Employee { 6 | // @withMoreTasks 7 | // task: Task[] = []; 8 | // } 9 | // const employee1 = new Employee(); 10 | // console.log(employee1); 11 | // const employee2 = new Employee(); 12 | // console.log(employee2); 13 | // function withMoreTasks( 14 | // target: undefined, 15 | // context: ClassFieldDecoratorContext 16 | // ) { 17 | // // V -> Task[] 18 | // return function (args: V) { 19 | // args.push({ name: "Added 1 task", level: "low" }); 20 | // args.push({ name: "Added 2 task", level: "medium" }); 21 | // args.push({ name: "Added 3 task", level: "complicated" }); 22 | // return args; 23 | // }; 24 | // } 25 | -------------------------------------------------------------------------------- /Decorators/app-field-demo.ts: -------------------------------------------------------------------------------- 1 | // type Task = { 2 | // name: string; 3 | // level: "low" | "medium" | "complicated"; 4 | // }; 5 | 6 | // class Employee { 7 | // @withMoreTasks 8 | // task: Task[] = []; 9 | // } 10 | 11 | // const employee1 = new Employee(); 12 | // console.log(employee1); 13 | 14 | // const employee2 = new Employee(); 15 | // console.log(employee2); 16 | 17 | // function withMoreTasks( 18 | // target: undefined, 19 | // context: ClassFieldDecoratorContext 20 | // ) { 21 | // // V -> Task[] 22 | // return function (args: V) { 23 | // args.push({ name: "Added 1 task", level: "low" }); 24 | // args.push({ name: "Added 2 task", level: "medium" }); 25 | // args.push({ name: "Added 3 task", level: "complicated" }); 26 | 27 | // return args; 28 | // }; 29 | // } 30 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/dist/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __importDefault = (this && this.__importDefault) || function (mod) { 3 | return (mod && mod.__esModule) ? mod : { "default": mod }; 4 | }; 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | const person_util_1 = require("./utils/person-util"); 7 | const person_util_2 = __importDefault(require("./utils/person-util")); 8 | const person1 = { age: 22, name: "mitko" }; 9 | const person2 = { name: "mitko2" }; 10 | const personOneCapitalized = (0, person_util_1.nameCapitalizer)(person1); 11 | console.log(person1); 12 | console.log(personOneCapitalized); 13 | const personTwoCapitalized = (0, person_util_1.nameCapitalizer)(person2); 14 | console.log(person2); 15 | console.log(personTwoCapitalized); 16 | console.log((0, person_util_2.default)()); 17 | -------------------------------------------------------------------------------- /Decorators/app-accessor-demo.ts: -------------------------------------------------------------------------------- 1 | class Person { 2 | @watchChange 3 | // Auto-accessor, unlike regular fields, define getters and setter on the class prototype 4 | accessor project: string = "Simple Project"; 5 | } 6 | 7 | const person = new Person(); 8 | console.log(person.project); 9 | person.project = "More complex project!"; 10 | 11 | type Accessor = { 12 | get: (this: T) => V; 13 | set: (this: T, value: V) => void; 14 | }; 15 | 16 | function watchChange( 17 | accessor: Accessor, 18 | context: ClassAccessorDecoratorContext 19 | ) { 20 | return { 21 | get: function (this: T) { 22 | return accessor.get.call(this); 23 | }, 24 | set: function (this: T, value: V) { 25 | console.log(`Set "${context.name.toString()}" to "${value}"`); 26 | accessor.set.call(this, value); 27 | }, 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "modules-demo", 3 | "version": "1.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "modules-demo", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "typescript": "^5.2.2" 13 | } 14 | }, 15 | "node_modules/typescript": { 16 | "version": "5.2.2", 17 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", 18 | "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", 19 | "dev": true, 20 | "bin": { 21 | "tsc": "bin/tsc", 22 | "tsserver": "bin/tsserver" 23 | }, 24 | "engines": { 25 | "node": ">=14.17" 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Interfaces-and-Generics/src/interfaces-demo/app-types-demo.ts: -------------------------------------------------------------------------------- 1 | type Mammal = { 2 | legsCount: number; 3 | furColor: string; 4 | }; 5 | 6 | type Animal = { 7 | eat: () => void; 8 | }; 9 | 10 | type Dog = Mammal & 11 | Animal & { 12 | name: string; 13 | }; 14 | 15 | interface DogOnwer { 16 | dogs: Dog[]; 17 | } 18 | 19 | type PersonTest = { 20 | dogOwner: DogOnwer; 21 | }; 22 | 23 | function getMammal(): Dog { 24 | const dog: Dog = { 25 | name: "Johny", 26 | legsCount: 4, 27 | furColor: "brown", 28 | eat: () => console.log("Dog is eating"), 29 | }; 30 | 31 | return dog; 32 | } 33 | 34 | // class Dog implements Mammal { 35 | // legsCount: number; 36 | // furColor: string; 37 | 38 | // /** 39 | // * 40 | // */ 41 | // constructor() { 42 | // this.legsCount = 4; 43 | // this.furColor = "yellow"; 44 | // } 45 | // } 46 | 47 | // const dog1 = new Dog(); 48 | -------------------------------------------------------------------------------- /Exam-Prep/02.LowestPricesInCitites/dist/index.js: -------------------------------------------------------------------------------- 1 | const inputData = [ 2 | "Sample Town | Sample Product | 1000", 3 | "Sample Town | Orange | 2", 4 | "Sample Town | Peach | 1", 5 | "Sofia | Orange | 3", 6 | "Sofia | Peach | 2", 7 | "New York | Sample Product | 1000.1", 8 | "New York | Burger | 10", 9 | ]; 10 | function solve(input) { 11 | const result = {}; 12 | for (const line of input) { 13 | const [town, product, price] = line.split(" | "); 14 | if (result[product] === undefined) { 15 | result[product] = {}; 16 | } 17 | result[product][town] = Number(price); 18 | } 19 | for (const [product, towns] of Object.entries(result)) { 20 | const sorted = Object.entries(towns).sort((a, b) => a[1] - b[1]); 21 | const [town, price] = sorted[0]; 22 | console.log(`${product} -> ${price} (${town})`); 23 | } 24 | } 25 | solve(inputData); 26 | -------------------------------------------------------------------------------- /Exam-Prep/01.Calculator/dist/index.js: -------------------------------------------------------------------------------- 1 | // function calc(firstNum: number, operator: string, secondNum: number) { 2 | // switch (operator) { 3 | // case "+": 4 | // return (firstNum + secondNum).toFixed(2); 5 | // case "-": 6 | // return (firstNum - secondNum).toFixed(2); 7 | // case "/": 8 | // return (firstNum / secondNum).toFixed(2); 9 | // case "*": 10 | // return (firstNum * secondNum).toFixed(2); 11 | // } 12 | // } 13 | function calc(firstNum, operator, secondNum) { 14 | const calculator = { 15 | "+": (firstNum + secondNum).toFixed(2), 16 | "-": (firstNum - secondNum).toFixed(2), 17 | "/": (firstNum / secondNum).toFixed(2), 18 | "*": (firstNum * secondNum).toFixed(2), 19 | }; 20 | return calculator[operator]; 21 | } 22 | console.log(calc(1, "+", 3)); 23 | console.log(calc(11, "-", 3)); 24 | console.log(calc(12, "/", 3)); 25 | console.log(calc(2, "*", 3)); 26 | -------------------------------------------------------------------------------- /Workshop/src/index.ts: -------------------------------------------------------------------------------- 1 | import { CONFIG } from "./constants"; 2 | import { router } from "./router"; 3 | import { PostsService } from "./services/postService"; 4 | import { UsersService } from "./services/userService"; 5 | import { User } from "./types/userTypes"; 6 | import { HtmlUtil } from "./utils/htmlUtil"; 7 | 8 | const rootDiv = document.getElementById("root"); 9 | 10 | const postsService = new PostsService(CONFIG.BASE_URL); 11 | 12 | const usersService = new UsersService(CONFIG.BASE_URL); 13 | const userId = 8; 14 | usersService.getSingleUser(userId, () => { 15 | postsService.getUserPosts(userId); 16 | }); 17 | 18 | // postsService.getAll(); 19 | 20 | // const userForUpdate: User = { 21 | // id: 1, 22 | // name: "Gosho 123", 23 | // phone: "123 123 125", 24 | // username: "goshoGoshov123", 25 | // email: "goshoGoshov123@abv.bgf", 26 | // }; 27 | 28 | // usersService.update(userForUpdate); 29 | // usersService.delete(3); 30 | 31 | HtmlUtil.render(rootDiv, router); 32 | -------------------------------------------------------------------------------- /Exam-Prep/01.Calculator/src/index.ts: -------------------------------------------------------------------------------- 1 | // function calc(firstNum: number, operator: string, secondNum: number) { 2 | // switch (operator) { 3 | // case "+": 4 | // return (firstNum + secondNum).toFixed(2); 5 | // case "-": 6 | // return (firstNum - secondNum).toFixed(2); 7 | // case "/": 8 | // return (firstNum / secondNum).toFixed(2); 9 | // case "*": 10 | // return (firstNum * secondNum).toFixed(2); 11 | // } 12 | // } 13 | 14 | type CalcType = { 15 | [key: string]: string; 16 | }; 17 | 18 | function calc(firstNum: number, operator: string, secondNum: number) { 19 | const calculator: CalcType = { 20 | "+": (firstNum + secondNum).toFixed(2), 21 | "-": (firstNum - secondNum).toFixed(2), 22 | "/": (firstNum / secondNum).toFixed(2), 23 | "*": (firstNum * secondNum).toFixed(2), 24 | }; 25 | 26 | return calculator[operator]; 27 | } 28 | 29 | console.log(calc(1, "+", 3)); 30 | console.log(calc(11, "-", 3)); 31 | console.log(calc(12, "/", 3)); 32 | console.log(calc(2, "*", 3)); 33 | -------------------------------------------------------------------------------- /Exam-Prep/02.LowestPricesInCitites/src/index.ts: -------------------------------------------------------------------------------- 1 | const inputData: string[] = [ 2 | "Sample Town | Sample Product | 1000", 3 | "Sample Town | Orange | 2", 4 | "Sample Town | Peach | 1", 5 | "Sofia | Orange | 3", 6 | "Sofia | Peach | 2", 7 | "New York | Sample Product | 1000.1", 8 | "New York | Burger | 10", 9 | ]; 10 | 11 | type NumberMap = { 12 | [key: string]: number; 13 | }; 14 | 15 | type ResultType = { 16 | [key: string]: NumberMap; 17 | }; 18 | 19 | function solve(input: string[]): void { 20 | const result: ResultType = {}; 21 | 22 | for (const line of input) { 23 | const [town, product, price] = line.split(" | "); 24 | 25 | if (result[product] === undefined) { 26 | result[product] = {}; 27 | } 28 | 29 | result[product][town] = Number(price); 30 | } 31 | 32 | for (const [product, towns] of Object.entries(result)) { 33 | const sorted = Object.entries(towns).sort((a, b) => a[1] - b[1]); 34 | const [town, price] = sorted[0]; 35 | 36 | console.log(`${product} -> ${price} (${town})`); 37 | } 38 | } 39 | 40 | solve(inputData); 41 | -------------------------------------------------------------------------------- /Workshop/src/services/httpService.ts: -------------------------------------------------------------------------------- 1 | import { fetchUtil } from "../utils/httpUtil"; 2 | 3 | export class HttpService { 4 | protected apiUrl: string; 5 | data = {} as T; 6 | dataCollection = [] as T[]; 7 | 8 | constructor(apiUrl: string) { 9 | this.apiUrl = apiUrl; 10 | } 11 | 12 | create(body: T) { 13 | fetchUtil(this.apiUrl, { 14 | method: "POST", 15 | body: JSON.stringify(body), 16 | headers: { 17 | "Content-type": "application/json; charset=UTF-8", 18 | }, 19 | }); 20 | } 21 | 22 | getAll() { 23 | fetchUtil(this.apiUrl); 24 | } 25 | 26 | getOne(id: number) { 27 | fetchUtil(`${this.apiUrl}/${id}`); 28 | } 29 | 30 | update(body: T) { 31 | fetchUtil(`${this.apiUrl}/${body.id}`, { 32 | method: "PUT", 33 | body: JSON.stringify(body), 34 | headers: { 35 | "Content-type": "application/json; charset=UTF-8", 36 | }, 37 | }); 38 | } 39 | 40 | delete(id: number) { 41 | fetchUtil(`${this.apiUrl}/${id}`, { method: "DELETE" }); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Workshop/src/utils/htmlUtil.ts: -------------------------------------------------------------------------------- 1 | import { RouterMap } from "../types/routerTypes"; 2 | 3 | export class HtmlUtil { 4 | static render(rootDiv: HTMLElement | null, router: RouterMap) { 5 | if (!rootDiv) { 6 | throw Error("Missing root element!"); 7 | } 8 | 9 | // On Init 10 | rootDiv.innerHTML = router[window.location.pathname]; 11 | 12 | // Listner for events 13 | HtmlUtil.allEventListeners(rootDiv, router); 14 | } 15 | 16 | static allEventListeners(rootDiv: HTMLElement, router: RouterMap) { 17 | // capture elements 18 | const usersAnchor: HTMLElement | null = document.getElementById("users"); 19 | const postsAnchor = document.getElementById("posts"); 20 | 21 | // event listeners attachement 22 | usersAnchor?.addEventListener("click", () => 23 | HtmlUtil.onNavigate(rootDiv, router, "/") 24 | ); 25 | 26 | postsAnchor?.addEventListener("click", () => 27 | HtmlUtil.onNavigate(rootDiv, router, "/post") 28 | ); 29 | } 30 | 31 | static onNavigate( 32 | rootDiv: HTMLElement | null, 33 | router: RouterMap, 34 | pathname: string 35 | ) { 36 | const { origin } = window.location; 37 | window.history.pushState({}, pathname, `${origin}${pathname}`); 38 | 39 | if (rootDiv) { 40 | rootDiv.innerHTML = router[pathname]; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/namespaces-demo/index.ts: -------------------------------------------------------------------------------- 1 | namespace PersonUtils { 2 | interface PersonDetails { 3 | name: string; 4 | } 5 | 6 | export class Person implements PersonDetails { 7 | name: string; 8 | 9 | constructor(name: string) { 10 | this.name = name; 11 | } 12 | 13 | getName() { 14 | return this.name; 15 | } 16 | } 17 | } 18 | 19 | class Person { 20 | name: string; 21 | 22 | constructor(name: string) { 23 | this.name = name; 24 | } 25 | 26 | getName() { 27 | return this.name; 28 | } 29 | } 30 | 31 | const p1 = new Person("Pesho1"); 32 | const p2 = new PersonUtils.Person("Pesho2"); 33 | 34 | /// 35 | namespace AnimalGroup { 36 | export class Dog extends Animal { 37 | constructor(furColor: string, numberOfLegs: number, type: string) { 38 | super(furColor, numberOfLegs, type); 39 | } 40 | 41 | getStuff() { 42 | const h = new HumanGroup.Human(); 43 | } 44 | } 45 | 46 | export interface PersonTest {} 47 | 48 | const P = 1; 49 | const x = () => 1; 50 | } 51 | 52 | const dogPenny = new AnimalGroup.Dog("brown", 4, "Penny"); 53 | 54 | namespace LibraryUtil { 55 | export namespace ReadFiles { 56 | export class AsyncRead {} 57 | } 58 | 59 | export namespace WriteFiles { 60 | export class AsyncWrite {} 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Decorators/app-method-demo.ts: -------------------------------------------------------------------------------- 1 | class Project { 2 | budget: number = 900; 3 | 4 | @withBudget(10) 5 | writeTest() { 6 | console.log("Test are important!"); 7 | } 8 | 9 | @withBudget(500) 10 | fixBugInProduction() { 11 | console.log("Fixing bug in production is expensive!"); 12 | } 13 | } 14 | 15 | const project = new Project(); 16 | project.writeTest(); 17 | project.fixBugInProduction(); 18 | project.fixBugInProduction(); 19 | project.writeTest(); 20 | project.writeTest(); 21 | project.writeTest(); 22 | console.log(project.budget); 23 | 24 | type WithBudget = { 25 | budget: number; 26 | }; 27 | 28 | function withBudget(actionBudget: number) { 29 | return function ( 30 | target: Function, 31 | context: ClassMethodDecoratorContext 32 | ) { 33 | return function (...args: any) { 34 | // cast the type 35 | const instance = this as T; // T -> our decorated class 36 | 37 | if (instance.budget > actionBudget) { 38 | instance.budget -= actionBudget; 39 | target.apply(instance, args); // call our method for instance with args 40 | } else { 41 | console.log( 42 | `Insufficient funds for ${context.name.toString()}. Required ${actionBudget}, availble ${ 43 | instance.budget 44 | }!` 45 | ); 46 | } 47 | }; 48 | }; 49 | } 50 | -------------------------------------------------------------------------------- /Exam-Prep/03.ClotheMagazine/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Magazine } from "./Magazine"; 2 | import { Cloth } from "./Cloth"; 3 | 4 | function main() { 5 | // Initialize the repository (Magazine) 6 | const magazine = new Magazine("Zara", 20); 7 | 8 | // Initialize entity (Cloth) 9 | const cloth1 = new Cloth("red", 36, "dress"); 10 | 11 | // Print Cloth 12 | console.log(cloth1.toString()); 13 | // Product: dress with size 36, color red 14 | 15 | // Add Cloth 16 | magazine.addCloth(cloth1); 17 | 18 | // Remove Cloth 19 | console.log(magazine.removeCloth("black")); // false 20 | 21 | const cloth2 = new Cloth("brown", 34, "t-shirt"); 22 | const cloth3 = new Cloth("blue", 32, "jeans"); 23 | 24 | // Add Cloth 25 | magazine.addCloth(cloth2); 26 | magazine.addCloth(cloth3); 27 | 28 | // Get smallest cloth 29 | const smallestCloth = magazine.getSmallestCloth(); 30 | console.log(smallestCloth?.toString()); 31 | // Product: jeans with size 32, color blue 32 | 33 | // Get Cloth 34 | const getCloth = magazine.getCloth("brown"); 35 | // Product: t-shirt with size 34, color brown 36 | console.log(getCloth?.toString()); 37 | 38 | console.log(magazine.report()); 39 | // Zara magazine contains: 40 | // Product: jeans with size 32, color blue 41 | // Product: t-shirt with size 34, color brown 42 | // Product: dress with size 36, color red 43 | } 44 | main(); 45 | -------------------------------------------------------------------------------- /Workshop/dist/css/style.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | font-family: sans-serif; 4 | margin: 0; 5 | height: 100%; 6 | } 7 | 8 | p { 9 | margin-block-start: 0; 10 | text-indent: 1rem; 11 | } 12 | 13 | hr { 14 | border: none; 15 | height: 1px; 16 | background-color: lightgray; 17 | width: 40px; 18 | margin: 1.5rem 0 1rem 0; 19 | } 20 | 21 | #wrapper { 22 | display: flex; 23 | height: 100%; 24 | } 25 | 26 | #root { 27 | flex-grow: 1; 28 | } 29 | 30 | .sidebar { 31 | display: flex; 32 | flex-direction: column; 33 | padding: 1rem; 34 | 35 | border-right: 1px solid lightgray; 36 | } 37 | 38 | .sidebar > a { 39 | margin: 0.5rem 0; 40 | } 41 | 42 | .page-container { 43 | display: flex; 44 | flex-direction: column; 45 | 46 | padding: 0 1rem; 47 | } 48 | 49 | .align-center { 50 | align-items: center; 51 | } 52 | 53 | .socials-container { 54 | display: flex; 55 | justify-content: space-between; 56 | } 57 | 58 | .socials-card { 59 | display: flex; 60 | align-items: center; 61 | 62 | border: 1px solid lightgray; 63 | border-radius: 0.5rem; 64 | padding: 0.5rem 1rem; 65 | margin: 1rem; 66 | 67 | text-decoration: none; 68 | color: unset; 69 | } 70 | 71 | .socials-card:hover { 72 | background-color: lightgray; 73 | } 74 | 75 | .socials-card > i { 76 | font-size: 1.5rem; 77 | margin-right: 0.5rem; 78 | } 79 | 80 | a:hover { 81 | background: grey; 82 | cursor: pointer; 83 | } 84 | -------------------------------------------------------------------------------- /Decorators/app-class-demo.ts: -------------------------------------------------------------------------------- 1 | @withEmploymentDateOnPrototype 2 | @withEmployementDate 3 | class Manager { 4 | task: string = "Simple task"; 5 | project: string = "Simple project"; 6 | 7 | constructor() { 8 | console.log("Manager class has initted!"); 9 | } 10 | } 11 | 12 | const manager = new Manager(); 13 | console.log(manager); 14 | console.log(manager.constructor.prototype); 15 | 16 | function withEmploymentDateOnPrototype( 17 | value: Function, 18 | context: ClassDecoratorContext 19 | ) { 20 | value.prototype.employementDateOnPrototype = new Date().toISOString(); 21 | } 22 | 23 | type Args = { new (...args: any[]): {} }; 24 | function withEmployementDate( 25 | baseClass: T, 26 | context: ClassDecoratorContext 27 | ) { 28 | return class extends baseClass { 29 | employementDate = new Date().toISOString(); 30 | 31 | constructor(...args: any[]) { 32 | super(...args); 33 | console.log("Adding employment date to " + baseClass.name); 34 | } 35 | }; 36 | } 37 | 38 | function printDecoratorData(value: Function, context: ClassDecoratorContext) { 39 | console.log({ value }); 40 | console.log({ context }); 41 | 42 | context.addInitializer(() => { 43 | console.log("Class initialized: " + context.name); 44 | }); 45 | } 46 | 47 | function seal(constructor: Function, context: ClassDecoratorContext) { 48 | Object.seal(constructor); 49 | Object.seal(constructor.prototype); 50 | } 51 | -------------------------------------------------------------------------------- /Exam-Prep/03.ClotheMagazine/src/Magazine.ts: -------------------------------------------------------------------------------- 1 | import { Cloth } from "./Cloth"; 2 | 3 | export class Magazine { 4 | type: string; 5 | capacity: number; 6 | clothes: Cloth[]; 7 | 8 | constructor(type: string, capacity: number) { 9 | this.type = type; 10 | this.capacity = capacity; 11 | this.clothes = []; 12 | } 13 | 14 | addCloth(cloth: Cloth): void { 15 | if (this.clothes.length < this.capacity) { 16 | this.clothes.push(cloth); 17 | } 18 | } 19 | 20 | removeCloth(color: string): boolean { 21 | const index = this.clothes.findIndex((c) => c.color === color); 22 | 23 | if (index !== -1) { 24 | this.clothes.splice(index, 1); 25 | return true; 26 | } 27 | 28 | return false; 29 | } 30 | 31 | getSmallestCloth(): Cloth { 32 | const smallestCloth = [...this.clothes].sort((a, b) => a.size - b.size)[0]; 33 | return smallestCloth; 34 | } 35 | 36 | getCloth(color: string): Cloth { 37 | const cloth = this.clothes.find((c) => c.color === color); 38 | return cloth; 39 | } 40 | 41 | getClothCount(): number { 42 | const count = this.clothes.length; 43 | return count; 44 | } 45 | 46 | report(): string { 47 | const sortedClothes = [...this.clothes].sort((a, b) => a.size - b.size); 48 | const clothesForReport = sortedClothes.map((c) => c.toString()).join("\n"); 49 | 50 | const report = `${this.type} magizne contains:\n${clothesForReport}`; 51 | return report; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Exam-Prep/03.ClotheMagazine/dist/Magazine.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.Magazine = void 0; 4 | class Magazine { 5 | constructor(type, capacity) { 6 | this.type = type; 7 | this.capacity = capacity; 8 | this.clothes = []; 9 | } 10 | addCloth(cloth) { 11 | if (this.clothes.length < this.capacity) { 12 | this.clothes.push(cloth); 13 | } 14 | } 15 | removeCloth(color) { 16 | const index = this.clothes.findIndex((c) => c.color === color); 17 | if (index !== -1) { 18 | this.clothes.splice(index, 1); 19 | return true; 20 | } 21 | return false; 22 | } 23 | getSmallestCloth() { 24 | const smallestCloth = [...this.clothes].sort((a, b) => a.size - b.size)[0]; 25 | return smallestCloth; 26 | } 27 | getCloth(color) { 28 | const cloth = this.clothes.find((c) => c.color === color); 29 | return cloth; 30 | } 31 | getClothCount() { 32 | const count = this.clothes.length; 33 | return count; 34 | } 35 | report() { 36 | const sortedClothes = [...this.clothes].sort((a, b) => a.size - b.size); 37 | const clothesForReport = sortedClothes.map((c) => c.toString()).join("\n"); 38 | const report = `${this.type} magizne contains:\n${clothesForReport}`; 39 | return report; 40 | } 41 | } 42 | exports.Magazine = Magazine; 43 | -------------------------------------------------------------------------------- /Exam-Prep/03.ClotheMagazine/dist/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | const Magazine_1 = require("./Magazine"); 4 | const Cloth_1 = require("./Cloth"); 5 | function main() { 6 | // Initialize the repository (Magazine) 7 | const magazine = new Magazine_1.Magazine("Zara", 20); 8 | // Initialize entity (Cloth) 9 | const cloth1 = new Cloth_1.Cloth("red", 36, "dress"); 10 | // Print Cloth 11 | console.log(cloth1.toString()); 12 | // Product: dress with size 36, color red 13 | // Add Cloth 14 | magazine.addCloth(cloth1); 15 | // Remove Cloth 16 | console.log(magazine.removeCloth("black")); // false 17 | const cloth2 = new Cloth_1.Cloth("brown", 34, "t-shirt"); 18 | const cloth3 = new Cloth_1.Cloth("blue", 32, "jeans"); 19 | // Add Cloth 20 | magazine.addCloth(cloth2); 21 | magazine.addCloth(cloth3); 22 | // Get smallest cloth 23 | const smallestCloth = magazine.getSmallestCloth(); 24 | console.log(smallestCloth?.toString()); 25 | // Product: jeans with size 32, color blue 26 | // Get Cloth 27 | const getCloth = magazine.getCloth("brown"); 28 | // Product: t-shirt with size 34, color brown 29 | console.log(getCloth?.toString()); 30 | console.log(magazine.report()); 31 | // Zara magazine contains: 32 | // Product: jeans with size 32, color blue 33 | // Product: t-shirt with size 34, color brown 34 | // Product: dress with size 36, color red 35 | } 36 | main(); 37 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/dist/utils/person-util.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 3 | if (k2 === undefined) k2 = k; 4 | var desc = Object.getOwnPropertyDescriptor(m, k); 5 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { 6 | desc = { enumerable: true, get: function() { return m[k]; } }; 7 | } 8 | Object.defineProperty(o, k2, desc); 9 | }) : (function(o, m, k, k2) { 10 | if (k2 === undefined) k2 = k; 11 | o[k2] = m[k]; 12 | })); 13 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { 14 | Object.defineProperty(o, "default", { enumerable: true, value: v }); 15 | }) : function(o, v) { 16 | o["default"] = v; 17 | }); 18 | var __importStar = (this && this.__importStar) || function (mod) { 19 | if (mod && mod.__esModule) return mod; 20 | var result = {}; 21 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); 22 | __setModuleDefault(result, mod); 23 | return result; 24 | }; 25 | Object.defineProperty(exports, "__esModule", { value: true }); 26 | exports.nameCapitalizer = void 0; 27 | const stringUtl = __importStar(require("./string-utils")); 28 | const tranformPersonNameToCapitalLetter = (person) => { 29 | const { name } = person; 30 | return Object.assign(Object.assign({}, person), { name: stringUtl.capitalizeFirstLetter(name) }); 31 | }; 32 | exports.nameCapitalizer = tranformPersonNameToCapitalLetter; 33 | function xx123() { 34 | return 10; 35 | } 36 | exports.default = xx123; 37 | -------------------------------------------------------------------------------- /Interfaces-and-Generics/src/interfaces-demo/app-interfaces-demo.ts: -------------------------------------------------------------------------------- 1 | // Contract 2 | interface UserDetails { 3 | firstName: "Tsveti" | "Gosho" | "Kaloyan"; 4 | lastName: string; 5 | } 6 | 7 | interface Human { 8 | legsCount: number; 9 | skinColor: string; 10 | } 11 | 12 | interface PersonDetails extends UserDetails, Human { 13 | fullName: string; 14 | } 15 | 16 | // Can be implemented by a class 17 | class Person implements PersonDetails { 18 | firstName: "Tsveti" | "Gosho" | "Kaloyan"; 19 | lastName: string; 20 | legsCount: number; 21 | skinColor: string; 22 | fullName: string; 23 | 24 | constructor( 25 | firstName: "Tsveti" | "Gosho" | "Kaloyan", 26 | lastName: string, 27 | legsCount: number, 28 | skinColor: string 29 | ) { 30 | this.firstName = firstName; 31 | this.lastName = lastName; 32 | this.legsCount = legsCount; 33 | this.skinColor = skinColor; 34 | 35 | this.fullName = this.firstName + " " + this.lastName; 36 | } 37 | } 38 | 39 | const personGosho = new Person("Gosho", "Kirilov", 2, "zelena"); 40 | 41 | // can be used as a type of a variable 42 | const user: UserDetails = { 43 | firstName: "Tsveti", 44 | lastName: "Petrov", 45 | }; 46 | 47 | // can be used as a return type 48 | // function getUsers(): UserDetails[] { 49 | // return [ 50 | // { 51 | // firstName: "Pesho", 52 | // lastName: "Petrov", 53 | // }, 54 | // { 55 | // firstName: "Ivan", 56 | // lastName: "Ivanov", 57 | // }, 58 | // { 59 | // firstName: "Mitko", 60 | // lastName: "Georgiev", 61 | // }, 62 | // ]; 63 | // } 64 | 65 | // const users = getUsers(); 66 | 67 | interface GetNameFunction { 68 | (param1: number, param2: string): string; 69 | } 70 | 71 | const getName: GetNameFunction = (param1: number, param2: string) => { 72 | return ""; 73 | }; 74 | -------------------------------------------------------------------------------- /Intro-TypeScript/dist/app.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"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"} -------------------------------------------------------------------------------- /Decorators/app-params-demo.js: -------------------------------------------------------------------------------- 1 | var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { 2 | function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } 3 | var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; 4 | var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; 5 | var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); 6 | var _, done = false; 7 | for (var i = decorators.length - 1; i >= 0; i--) { 8 | var context = {}; 9 | for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; 10 | for (var p in contextIn.access) context.access[p] = contextIn.access[p]; 11 | context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; 12 | var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); 13 | if (kind === "accessor") { 14 | if (result === void 0) continue; 15 | if (result === null || typeof result !== "object") throw new TypeError("Object expected"); 16 | if (_ = accept(result.get)) descriptor.get = _; 17 | if (_ = accept(result.set)) descriptor.set = _; 18 | if (_ = accept(result.init)) initializers.unshift(_); 19 | } 20 | else if (_ = accept(result)) { 21 | if (kind === "field") initializers.unshift(_); 22 | else descriptor[key] = _; 23 | } 24 | } 25 | if (target) Object.defineProperty(target, contextIn.name, descriptor); 26 | done = true; 27 | }; 28 | var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { 29 | var useValue = arguments.length > 2; 30 | for (var i = 0; i < initializers.length; i++) { 31 | value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); 32 | } 33 | return useValue ? value : void 0; 34 | }; 35 | let Example = (() => { 36 | let _instanceExtraInitializers = []; 37 | let _someMethod_decorators; 38 | return class Example { 39 | static { 40 | const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; 41 | _someMethod_decorators = [validateParams]; 42 | __esDecorate(this, null, _someMethod_decorators, { kind: "method", name: "someMethod", static: false, private: false, access: { has: obj => "someMethod" in obj, get: obj => obj.someMethod }, metadata: _metadata }, null, _instanceExtraInitializers); 43 | if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); 44 | } 45 | someMethod(arg1, arg2) { 46 | console.log(`Recieved params: ${arg1}, ${arg2}`); 47 | } 48 | constructor() { 49 | __runInitializers(this, _instanceExtraInitializers); 50 | } 51 | }; 52 | })(); 53 | function validateParams(target, context) { 54 | return function (...args) { 55 | for (let i = 0; i < args.length; i++) { 56 | const currentArg = args[i]; 57 | if (currentArg === undefined || currentArg === null) { 58 | throw new Error(`Parameter at index ${i} is invalid!`); 59 | } 60 | target.apply(this, args); 61 | } 62 | }; 63 | } 64 | const exampleInstance = new Example(); 65 | exampleInstance.someMethod("Hi", 12); 66 | -------------------------------------------------------------------------------- /Decorators/app-accessor-demo.js: -------------------------------------------------------------------------------- 1 | var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { 2 | function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } 3 | var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; 4 | var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; 5 | var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); 6 | var _, done = false; 7 | for (var i = decorators.length - 1; i >= 0; i--) { 8 | var context = {}; 9 | for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; 10 | for (var p in contextIn.access) context.access[p] = contextIn.access[p]; 11 | context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; 12 | var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); 13 | if (kind === "accessor") { 14 | if (result === void 0) continue; 15 | if (result === null || typeof result !== "object") throw new TypeError("Object expected"); 16 | if (_ = accept(result.get)) descriptor.get = _; 17 | if (_ = accept(result.set)) descriptor.set = _; 18 | if (_ = accept(result.init)) initializers.unshift(_); 19 | } 20 | else if (_ = accept(result)) { 21 | if (kind === "field") initializers.unshift(_); 22 | else descriptor[key] = _; 23 | } 24 | } 25 | if (target) Object.defineProperty(target, contextIn.name, descriptor); 26 | done = true; 27 | }; 28 | var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { 29 | var useValue = arguments.length > 2; 30 | for (var i = 0; i < initializers.length; i++) { 31 | value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); 32 | } 33 | return useValue ? value : void 0; 34 | }; 35 | let Person = (() => { 36 | let _instanceExtraInitializers = []; 37 | let _project_decorators; 38 | let _project_initializers = []; 39 | return class Person { 40 | static { 41 | const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; 42 | _project_decorators = [watchChange]; 43 | __esDecorate(this, null, _project_decorators, { kind: "accessor", name: "project", static: false, private: false, access: { has: obj => "project" in obj, get: obj => obj.project, set: (obj, value) => { obj.project = value; } }, metadata: _metadata }, _project_initializers, _instanceExtraInitializers); 44 | if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); 45 | } 46 | #project_accessor_storage = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _project_initializers, "Simple Project")); 47 | get project() { return this.#project_accessor_storage; } 48 | set project(value) { this.#project_accessor_storage = value; } 49 | }; 50 | })(); 51 | const person = new Person(); 52 | console.log(person.project); 53 | person.project = "More complex project!"; 54 | function watchChange(accessor, context) { 55 | return { 56 | get: function () { 57 | return accessor.get.call(this); 58 | }, 59 | set: function (value) { 60 | console.log(`Set "${context.name.toString()}" to "${value}"`); 61 | accessor.set.call(this, value); 62 | }, 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /TypeScript-OOP/dist/app.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"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"} -------------------------------------------------------------------------------- /Decorators/app-factory-demo.js: -------------------------------------------------------------------------------- 1 | var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { 2 | function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } 3 | var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; 4 | var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; 5 | var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); 6 | var _, done = false; 7 | for (var i = decorators.length - 1; i >= 0; i--) { 8 | var context = {}; 9 | for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; 10 | for (var p in contextIn.access) context.access[p] = contextIn.access[p]; 11 | context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; 12 | var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); 13 | if (kind === "accessor") { 14 | if (result === void 0) continue; 15 | if (result === null || typeof result !== "object") throw new TypeError("Object expected"); 16 | if (_ = accept(result.get)) descriptor.get = _; 17 | if (_ = accept(result.set)) descriptor.set = _; 18 | if (_ = accept(result.init)) initializers.unshift(_); 19 | } 20 | else if (_ = accept(result)) { 21 | if (kind === "field") initializers.unshift(_); 22 | else descriptor[key] = _; 23 | } 24 | } 25 | if (target) Object.defineProperty(target, contextIn.name, descriptor); 26 | done = true; 27 | }; 28 | var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { 29 | var useValue = arguments.length > 2; 30 | for (var i = 0; i < initializers.length; i++) { 31 | value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); 32 | } 33 | return useValue ? value : void 0; 34 | }; 35 | let Employee = (() => { 36 | let _instanceExtraInitializers = []; 37 | let _tasks_decorators; 38 | let _tasks_initializers = []; 39 | let _extraTasks_decorators; 40 | let _extraTasks_initializers = []; 41 | return class Employee { 42 | static { 43 | const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; 44 | _tasks_decorators = [withTask({ name: "Task1 ", level: "complicated" })]; 45 | _extraTasks_decorators = [withComplicatedTask()]; 46 | __esDecorate(null, null, _tasks_decorators, { kind: "field", name: "tasks", static: false, private: false, access: { has: obj => "tasks" in obj, get: obj => obj.tasks, set: (obj, value) => { obj.tasks = value; } }, metadata: _metadata }, _tasks_initializers, _instanceExtraInitializers); 47 | __esDecorate(null, null, _extraTasks_decorators, { kind: "field", name: "extraTasks", static: false, private: false, access: { has: obj => "extraTasks" in obj, get: obj => obj.extraTasks, set: (obj, value) => { obj.extraTasks = value; } }, metadata: _metadata }, _extraTasks_initializers, _instanceExtraInitializers); 48 | if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); 49 | } 50 | tasks = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _tasks_initializers, [])); 51 | extraTasks = __runInitializers(this, _extraTasks_initializers, []); 52 | }; 53 | })(); 54 | const employee = new Employee(); 55 | console.log(employee); 56 | function withTask(task) { 57 | return function (target, context) { 58 | return function (args) { 59 | args.push(task); 60 | return args; 61 | }; 62 | }; 63 | } 64 | function withComplicatedTask() { 65 | return withTask({ name: "Some Other Task", level: "complicated" }); 66 | } 67 | -------------------------------------------------------------------------------- /Intro-TypeScript/dist/app.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | let greetingsMessage = "Hello"; 3 | greetingsMessage = "Ok"; 4 | greetingsMessage = `Ok (Updated) ${123}`; 5 | // greetingsMessage = 11; 6 | // console.log("string", greetingsMessage); 7 | let numberOfHouses = 4; 8 | numberOfHouses = 10100010111; 9 | numberOfHouses = 7e3; 10 | numberOfHouses = 3.14; 11 | // numberOfHouses = "Pesho 123"; 12 | // console.log("number", numberOfHouses); 13 | let isDog = true; 14 | isDog = false; 15 | isDog = 5 > 2; 16 | isDog = [1, 2, 3, 4].some((e) => e === 1); 17 | // 1/0 are not mapped to booleans true/false 18 | // isDog = { name: "Kircho", breed: "nemska ovcharka" }; 19 | // console.log("boolean", isDog); 20 | let uniqueSymbol = Symbol("myUniqueSymbol"); 21 | let anotherUniqueSymbol = Symbol("myUniqueSymbol"); 22 | const areEqual = uniqueSymbol === anotherUniqueSymbol; 23 | // console.log("symbol - areEqual", areEqual); 24 | let person; 25 | // person = 123; 26 | // console.log("undefinded", person); 27 | let dogs = null; 28 | // dogs = 123; 29 | // console.log("null", dogs); 30 | const arrOfNumbers = [1, 2, 3, 4]; 31 | // console.log("array of numbers", arrOfNumbers); 32 | const arrOfRandomStrings = ["Pesho", "Dog", "Mice", "Card"]; 33 | // console.log("array of string", arrOfRandomStrings); 34 | const arrOfBools = [true, false, true]; 35 | const arrOfObj = [ 36 | { name: "Pesho2", age: 33 }, 37 | { name: "Pesho1", age: 12 }, 38 | ]; 39 | // console.log("array of objects", arrOfObj); 40 | let numAndStrTuples = [18, "Pesho"]; 41 | // key value 42 | numAndStrTuples = [1, "Mitko"]; 43 | // console.log("number and string tuples ", numAndStrTuples); 44 | // enum DaysOfWorkWeek { 45 | // Monday, // 0 46 | // Tuesday, // 1 47 | // Wednesday, // 2 48 | // Thursday, // 3 49 | // Friday, // 4 50 | // } 51 | // console.log("enum", DaysOfWorkWeek.Wednesday); 52 | var DaysOfWorkWeek; 53 | (function (DaysOfWorkWeek) { 54 | DaysOfWorkWeek[DaysOfWorkWeek["Monday"] = 1200] = "Monday"; 55 | DaysOfWorkWeek["Tuesday"] = "Kuche"; 56 | DaysOfWorkWeek[DaysOfWorkWeek["Wednesday"] = 300] = "Wednesday"; 57 | DaysOfWorkWeek[DaysOfWorkWeek["Thursday"] = 4] = "Thursday"; 58 | DaysOfWorkWeek[DaysOfWorkWeek["Friday"] = 5] = "Friday"; 59 | })(DaysOfWorkWeek || (DaysOfWorkWeek = {})); 60 | // console.log("enum", DaysOfWorkWeek.Monday); 61 | // console.log("enum", DaysOfWorkWeek.Tuesday); 62 | // console.log("enum", DaysOfWorkWeek.Wednesday); 63 | let a = 5; 64 | a = "Poker"; 65 | a = { name: "Gosho" }; 66 | a = [{ name: "Gosho" }, { name: "Gosho2" }]; 67 | a = null; 68 | // console.log("any", a); 69 | let b = 5; 70 | b = "Poker"; 71 | b = { name: "Gosho" }; 72 | b = [{ name: "Gosho" }, { name: "Gosho2" }]; 73 | b = null; 74 | // console.log("unknown", b); 75 | function greetings(name) { 76 | console.log(`Hello, ${name}! This is 'void' example in TS!`); 77 | } 78 | // greetings("Pesho"); 79 | function printPersonDetail(name, age) { 80 | // if (typeof age !== "undefined") { 81 | return `Hello ${name}! You are ${age} y/o.`; 82 | // } 83 | // return "Hello " + name; 84 | } 85 | // console.log(printPersonDetail("Mitko")); 86 | // console.log(printPersonDetail("Pesho", 18)); 87 | // let personsArray: string[] | null = null; 88 | // function fetchPersons() { 89 | // personsArray = ["Mitko", "Pesho", "Kiro"]; 90 | // } 91 | // console.log("personArray before", personsArray); 92 | // fetchPersons(); 93 | // console.log("personArray after", personsArray); 94 | let test = 1; 95 | test = [1, 2, 3]; 96 | const obj = { name: " Pesho", fullName: "Pesho Todorv" }; 97 | // console.log("intersection", obj); 98 | let statusMsg; 99 | statusMsg = "success"; 100 | statusMsg = "error"; 101 | const catPesho = { 102 | breed: "ulichna", 103 | weigth: 12, 104 | name: "Pesho", 105 | age: 3, 106 | }; 107 | const point = { x: 22, y: -12 }; 108 | const newPoint = {}; 109 | Object.keys(point).forEach((key) => { 110 | newPoint[key] = point[key] * 10; 111 | }); 112 | // console.log("demo keyof ", newPoint); 113 | // type TreeNode { 114 | // value: number; 115 | // left?: TreeNode; 116 | // right?: TreeNode 117 | // } 118 | // Recursive Types 119 | //# sourceMappingURL=app.js.map -------------------------------------------------------------------------------- /Decorators/app-class-demo.js: -------------------------------------------------------------------------------- 1 | var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { 2 | function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } 3 | var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; 4 | var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; 5 | var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); 6 | var _, done = false; 7 | for (var i = decorators.length - 1; i >= 0; i--) { 8 | var context = {}; 9 | for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; 10 | for (var p in contextIn.access) context.access[p] = contextIn.access[p]; 11 | context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; 12 | var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); 13 | if (kind === "accessor") { 14 | if (result === void 0) continue; 15 | if (result === null || typeof result !== "object") throw new TypeError("Object expected"); 16 | if (_ = accept(result.get)) descriptor.get = _; 17 | if (_ = accept(result.set)) descriptor.set = _; 18 | if (_ = accept(result.init)) initializers.unshift(_); 19 | } 20 | else if (_ = accept(result)) { 21 | if (kind === "field") initializers.unshift(_); 22 | else descriptor[key] = _; 23 | } 24 | } 25 | if (target) Object.defineProperty(target, contextIn.name, descriptor); 26 | done = true; 27 | }; 28 | var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { 29 | var useValue = arguments.length > 2; 30 | for (var i = 0; i < initializers.length; i++) { 31 | value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); 32 | } 33 | return useValue ? value : void 0; 34 | }; 35 | let Manager = (() => { 36 | let _classDecorators = [withEmploymentDateOnPrototype, withEmployementDate]; 37 | let _classDescriptor; 38 | let _classExtraInitializers = []; 39 | let _classThis; 40 | var Manager = class { 41 | static { _classThis = this; } 42 | static { 43 | const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; 44 | __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); 45 | Manager = _classThis = _classDescriptor.value; 46 | if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); 47 | __runInitializers(_classThis, _classExtraInitializers); 48 | } 49 | task = "Simple task"; 50 | project = "Simple project"; 51 | constructor() { 52 | console.log("Manager class has initted!"); 53 | } 54 | }; 55 | return Manager = _classThis; 56 | })(); 57 | const manager = new Manager(); 58 | console.log(manager); 59 | console.log(manager.constructor.prototype); 60 | function withEmploymentDateOnPrototype(value, context) { 61 | value.prototype.employementDateOnPrototype = new Date().toISOString(); 62 | } 63 | function withEmployementDate(baseClass, context) { 64 | return class extends baseClass { 65 | employementDate = new Date().toISOString(); 66 | constructor(...args) { 67 | super(...args); 68 | console.log("Adding employment date to " + baseClass.name); 69 | } 70 | }; 71 | } 72 | function printDecoratorData(value, context) { 73 | console.log({ value }); 74 | console.log({ context }); 75 | context.addInitializer(() => { 76 | console.log("Class initialized: " + context.name); 77 | }); 78 | } 79 | function seal(constructor, context) { 80 | Object.seal(constructor); 81 | Object.seal(constructor.prototype); 82 | } 83 | -------------------------------------------------------------------------------- /Decorators/app-method-demo.js: -------------------------------------------------------------------------------- 1 | var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { 2 | var useValue = arguments.length > 2; 3 | for (var i = 0; i < initializers.length; i++) { 4 | value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); 5 | } 6 | return useValue ? value : void 0; 7 | }; 8 | var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { 9 | function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } 10 | var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; 11 | var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; 12 | var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); 13 | var _, done = false; 14 | for (var i = decorators.length - 1; i >= 0; i--) { 15 | var context = {}; 16 | for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; 17 | for (var p in contextIn.access) context.access[p] = contextIn.access[p]; 18 | context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; 19 | var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); 20 | if (kind === "accessor") { 21 | if (result === void 0) continue; 22 | if (result === null || typeof result !== "object") throw new TypeError("Object expected"); 23 | if (_ = accept(result.get)) descriptor.get = _; 24 | if (_ = accept(result.set)) descriptor.set = _; 25 | if (_ = accept(result.init)) initializers.unshift(_); 26 | } 27 | else if (_ = accept(result)) { 28 | if (kind === "field") initializers.unshift(_); 29 | else descriptor[key] = _; 30 | } 31 | } 32 | if (target) Object.defineProperty(target, contextIn.name, descriptor); 33 | done = true; 34 | }; 35 | let Project = (() => { 36 | let _instanceExtraInitializers = []; 37 | let _writeTest_decorators; 38 | let _fixBugInProduction_decorators; 39 | return class Project { 40 | static { 41 | const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; 42 | _writeTest_decorators = [withBudget(10)]; 43 | _fixBugInProduction_decorators = [withBudget(500)]; 44 | __esDecorate(this, null, _writeTest_decorators, { kind: "method", name: "writeTest", static: false, private: false, access: { has: obj => "writeTest" in obj, get: obj => obj.writeTest }, metadata: _metadata }, null, _instanceExtraInitializers); 45 | __esDecorate(this, null, _fixBugInProduction_decorators, { kind: "method", name: "fixBugInProduction", static: false, private: false, access: { has: obj => "fixBugInProduction" in obj, get: obj => obj.fixBugInProduction }, metadata: _metadata }, null, _instanceExtraInitializers); 46 | if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); 47 | } 48 | budget = (__runInitializers(this, _instanceExtraInitializers), 900); 49 | writeTest() { 50 | console.log("Test are important!"); 51 | } 52 | fixBugInProduction() { 53 | console.log("Fixing bug in production is expensive!"); 54 | } 55 | }; 56 | })(); 57 | const project = new Project(); 58 | project.writeTest(); 59 | project.fixBugInProduction(); 60 | project.fixBugInProduction(); 61 | project.writeTest(); 62 | project.writeTest(); 63 | project.writeTest(); 64 | console.log(project.budget); 65 | function withBudget(actionBudget) { 66 | return function (target, context) { 67 | return function (...args) { 68 | // cast the type 69 | const instance = this; // T -> our decorated class 70 | if (instance.budget > actionBudget) { 71 | instance.budget -= actionBudget; 72 | target.apply(instance, args); // call our method for instance with args 73 | } 74 | else { 75 | console.log(`Insufficient funds for ${context.name.toString()}. Required ${actionBudget}, availble ${instance.budget}!`); 76 | } 77 | }; 78 | }; 79 | } 80 | -------------------------------------------------------------------------------- /Intro-TypeScript/src/app.ts: -------------------------------------------------------------------------------- 1 | let greetingsMessage: string = "Hello"; 2 | greetingsMessage = "Ok"; 3 | greetingsMessage = `Ok (Updated) ${123}`; 4 | // greetingsMessage = 11; 5 | // console.log("string", greetingsMessage); 6 | 7 | let numberOfHouses: number = 4; 8 | numberOfHouses = 10100010111; 9 | numberOfHouses = 7e3; 10 | numberOfHouses = 3.14; 11 | // numberOfHouses = "Pesho 123"; 12 | // console.log("number", numberOfHouses); 13 | 14 | let isDog: boolean = true; 15 | isDog = false; 16 | isDog = 5 > 2; 17 | isDog = [1, 2, 3, 4].some((e) => e === 1); 18 | // 1/0 are not mapped to booleans true/false 19 | // isDog = { name: "Kircho", breed: "nemska ovcharka" }; 20 | // console.log("boolean", isDog); 21 | 22 | let uniqueSymbol: Symbol = Symbol("myUniqueSymbol"); 23 | let anotherUniqueSymbol = Symbol("myUniqueSymbol"); 24 | const areEqual = uniqueSymbol === anotherUniqueSymbol; 25 | // console.log("symbol - areEqual", areEqual); 26 | 27 | let person: undefined; 28 | // person = 123; 29 | // console.log("undefinded", person); 30 | 31 | let dogs: null = null; 32 | // dogs = 123; 33 | // console.log("null", dogs); 34 | 35 | const arrOfNumbers: number[] = [1, 2, 3, 4]; 36 | // console.log("array of numbers", arrOfNumbers); 37 | const arrOfRandomStrings: string[] = ["Pesho", "Dog", "Mice", "Card"]; 38 | // console.log("array of string", arrOfRandomStrings); 39 | const arrOfBools: boolean[] = [true, false, true]; 40 | // console.log("array of boolean", arrOfBools); 41 | 42 | type Person = { 43 | name: string; 44 | age: number; 45 | }; 46 | const arrOfObj: Person[] = [ 47 | { name: "Pesho2", age: 33 }, 48 | { name: "Pesho1", age: 12 }, 49 | ]; 50 | // console.log("array of objects", arrOfObj); 51 | 52 | let numAndStrTuples: [number, string] = [18, "Pesho"]; 53 | // key value 54 | numAndStrTuples = [1, "Mitko"]; 55 | // console.log("number and string tuples ", numAndStrTuples); 56 | 57 | // enum DaysOfWorkWeek { 58 | // Monday, // 0 59 | // Tuesday, // 1 60 | // Wednesday, // 2 61 | // Thursday, // 3 62 | // Friday, // 4 63 | // } 64 | // console.log("enum", DaysOfWorkWeek.Wednesday); 65 | 66 | enum DaysOfWorkWeek { 67 | Monday = 1200, // 68 | Tuesday = "Kuche", // 69 | Wednesday = 300, // 70 | Thursday = 4, // 71 | Friday = 5, // 72 | } 73 | // console.log("enum", DaysOfWorkWeek.Monday); 74 | // console.log("enum", DaysOfWorkWeek.Tuesday); 75 | // console.log("enum", DaysOfWorkWeek.Wednesday); 76 | 77 | let a: any = 5; 78 | a = "Poker"; 79 | a = { name: "Gosho" }; 80 | a = [{ name: "Gosho" }, { name: "Gosho2" }]; 81 | a = null; 82 | // console.log("any", a); 83 | 84 | let b: unknown = 5; 85 | b = "Poker"; 86 | b = { name: "Gosho" }; 87 | b = [{ name: "Gosho" }, { name: "Gosho2" }]; 88 | b = null; 89 | // console.log("unknown", b); 90 | 91 | function greetings(name: string): void { 92 | console.log(`Hello, ${name}! This is 'void' example in TS!`); 93 | } 94 | // greetings("Pesho"); 95 | 96 | function printPersonDetail(name: string, age?: number): string | number { 97 | // if (typeof age !== "undefined") { 98 | return `Hello ${name}! You are ${age} y/o.`; 99 | // } 100 | 101 | // return "Hello " + name; 102 | } 103 | 104 | // console.log(printPersonDetail("Mitko")); 105 | // console.log(printPersonDetail("Pesho", 18)); 106 | 107 | // let personsArray: string[] | null = null; 108 | 109 | // function fetchPersons() { 110 | // personsArray = ["Mitko", "Pesho", "Kiro"]; 111 | // } 112 | // console.log("personArray before", personsArray); 113 | // fetchPersons(); 114 | // console.log("personArray after", personsArray); 115 | 116 | let test: number | number[] = 1; 117 | test = [1, 2, 3]; 118 | // console.log("union types", test); 119 | 120 | // Aliases 121 | type Dog = { name: string }; 122 | type Dog2 = { fullName: string }; 123 | 124 | const obj: Dog & Dog2 = { name: " Pesho", fullName: "Pesho Todorv" }; 125 | // console.log("intersection", obj); 126 | 127 | let statusMsg: "success" | "error"; 128 | statusMsg = "success"; 129 | statusMsg = "error"; 130 | // console.log("literal msg", statusMsg); 131 | 132 | type Age = number; 133 | 134 | type Cat = { 135 | breed: string; 136 | weigth: number; 137 | name: string; 138 | age?: Age; 139 | }; 140 | 141 | const catPesho: Cat = { 142 | breed: "ulichna", 143 | weigth: 12, 144 | name: "Pesho", 145 | age: 3, 146 | }; 147 | 148 | // console.log("aliases", catPesho); 149 | 150 | type Point = { x: number; y: number }; 151 | 152 | const point: Point = { x: 22, y: -12 }; 153 | 154 | const newPoint = {} as Point; 155 | Object.keys(point).forEach((key) => { 156 | newPoint[key as keyof Point] = point[key as keyof Point] * 10; 157 | }); 158 | 159 | // console.log("demo keyof ", newPoint); 160 | 161 | // type TreeNode { 162 | // value: number; 163 | // left?: TreeNode; 164 | // right?: TreeNode 165 | // } 166 | // Recursive Types 167 | -------------------------------------------------------------------------------- /Interfaces-and-Generics/dist/app-generics-demo.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // console.log(123); 3 | // const getTestGenerics = (paramId: T): T => { 4 | // return paramId; 5 | // }; 6 | // const id1 = getTestGenerics(1); 7 | // const id2 = getTestGenerics("ZXacsadsa123"); 8 | // const ids = getTestGenerics([1, 2, 3]); 9 | // type UserData = { 10 | // name: string; 11 | // age: number; 12 | // address: string; 13 | // id: T; 14 | // }; 15 | // const x = getTestGenerics>({ 16 | // name: "Mitko", 17 | // age: 12, 18 | // address: "Sofia, Bulgaria", 19 | // id: 1, 20 | // }); 21 | // const y = getTestGenerics>({ 22 | // name: "Mitko", 23 | // age: 12, 24 | // address: "Sofia, Bulgaria", 25 | // id: "xyz123", 26 | // }); 27 | // const generateAndAttachId = (obj: T) => { 28 | // const objId = Math.random(); 29 | // return { ...obj, id: objId }; 30 | // }; 31 | // type PersonObjectDetails = { 32 | // name: string; 33 | // age: number; 34 | // city: string; 35 | // }; 36 | // const person: PersonObjectDetails = { name: "Mitko", age: 21, city: "Lovech" }; 37 | // const personWithId = generateAndAttachId(person); 38 | // console.log(personWithId); 39 | // type AnimalObjectDetails = { 40 | // legsCount: number; 41 | // furColor: string; 42 | // name: string; 43 | // }; 44 | // const animal: AnimalObjectDetails = { 45 | // legsCount: 4, 46 | // furColor: "blonde", 47 | // name: "fluffy", 48 | // }; 49 | // const animalWithId = generateAndAttachId(animal); 50 | // console.log(animalWithId); 51 | // interface DocumentObject { 52 | // id: number; 53 | // name: string; 54 | // data: T; 55 | // } 56 | // const doc1: DocumentObject<{ name: string }[]> = { 57 | // id: 1, 58 | // name: "flowers", 59 | // data: [{ name: "flower1" }, { name: "flower2" }], 60 | // }; 61 | // const doc2: DocumentObject<{ name: string; age: number; address: string }> = { 62 | // id: 2, 63 | // name: "person", 64 | // data: { name: "Pesho", age: 12, address: "Bulgaira" }, 65 | // }; 66 | // const doc3: DocumentObject = { 67 | // id: 3, 68 | // name: "testr", 69 | // data: 1, 70 | // }; 71 | // function echo(arg: T): T { 72 | // console.log(typeof arg); 73 | // return arg; 74 | // } 75 | // console.log("-----------------"); 76 | // echo(1); 77 | // echo("string"); 78 | // echo(true); 79 | // echo([1, 2, 3]); 80 | // const takeLast = (array: T[]): T => { 81 | // return array[array.length - 1]; 82 | // }; 83 | // console.log(takeLast([1, 2, 3, 4])); 84 | // console.log(takeLast(["a", "b", "c", "d"])); 85 | // console.log(takeLast([true, false, true])); 86 | // console.log(takeLast([{ a: 1 }, { a: 2 }, { a: 3 }])); 87 | // const obj = { a: 1, b: 2, c: 3 }; 88 | // console.log(Object.entries(obj)); 89 | // const makeTuples = (a: T, b: Z): (T | Z)[] => { 90 | // return [a, b]; 91 | // }; 92 | // console.log(makeTuples("a", true)); 93 | // console.log(makeTuples(1, "true")); 94 | // type GenericConstructor = { 95 | // (arg1: T, arg2: V): [T, V]; 96 | // }; 97 | // const generateFn: GenericConstructor = ( 98 | // arg1: T, 99 | // arg2: V 100 | // ) => { 101 | // return [arg1, arg2]; 102 | // }; 103 | // const output = generateFn("Hello", 55); 104 | // console.log(output); 105 | class Collection { 106 | constructor(...elements) { 107 | this.data = elements; 108 | } 109 | addElement(el) { 110 | this.data.push(el); 111 | } 112 | removeElemet(el) { 113 | const index = this.data.indexOf(el); 114 | if (index > -1) { 115 | this.data.splice(index, 1); 116 | } 117 | } 118 | } 119 | // const numberCollection = new Collection(1, 2, 3, 4); 120 | // console.log(numberCollection.data); 121 | // numberCollection.addElement(99); 122 | // numberCollection.removeElemet(2); 123 | // console.log(numberCollection.data); 124 | // const stringCollection = new Collection("a", "b", "c", "d"); 125 | // console.log(stringCollection.data); 126 | // stringCollection.addElement("Pokemon"); 127 | // stringCollection.removeElemet("c"); 128 | // console.log(stringCollection.data); 129 | // class Test { 130 | // first: F; 131 | // second: S; 132 | // constructor(first: F, second: S) { 133 | // this.first = first; 134 | // this.second = second; 135 | // } 136 | // getConcatinatedArguments() { 137 | // return `My first param: ${this.first} and my second param: ${this.second}`; 138 | // } 139 | // } 140 | // const test1 = new Test(1, "Gosho"); 141 | // console.log(test1.getConcatinatedArguments()); 142 | // const test2 = new Test("Zebra", { success: true }); 143 | // console.log(test2.getConcatinatedArguments()); 144 | // const person = { 145 | // age: 33, 146 | // addres: "Sofia, Bulgaria", 147 | // firstName: "Pesho", 148 | // lastName: "Ivanov", 149 | // }; 150 | // interface FullName { 151 | // firstName: string; 152 | // lastName: string; 153 | // } 154 | // function fullName(obj: T) { 155 | // return `The full name of the user is ${obj.firstName} ${obj.lastName}!`; 156 | // } 157 | // console.log(fullName(person)); 158 | // class BankAccount { 159 | // private static id: number; 160 | // private balance: number = 0; 161 | // private interestRate: number = 0.02; 162 | // constructor() { 163 | // BankAccount.id += 1; 164 | // } 165 | // public setInterestRate(interestRate: number) { 166 | // this.interestRate = interestRate; 167 | // } 168 | // public getInterest(id: number, years: number) { 169 | // return this.interestRate; 170 | // } 171 | // public deposit(id: number, amount: number) { 172 | // this.balance = amount; 173 | // } 174 | // } 175 | // to have for sure -> {age: number} 176 | const getSmth = (obj) => { 177 | return obj; 178 | }; 179 | getSmth({ username: "123", password: "123", a: 1, b: 2, c: 3 }); 180 | -------------------------------------------------------------------------------- /Interfaces-and-Generics/src/app-generics-demo.ts: -------------------------------------------------------------------------------- 1 | // console.log(123); 2 | 3 | // const getTestGenerics = (paramId: T): T => { 4 | // return paramId; 5 | // }; 6 | 7 | // const id1 = getTestGenerics(1); 8 | // const id2 = getTestGenerics("ZXacsadsa123"); 9 | // const ids = getTestGenerics([1, 2, 3]); 10 | 11 | // type UserData = { 12 | // name: string; 13 | // age: number; 14 | // address: string; 15 | // id: T; 16 | // }; 17 | 18 | // const x = getTestGenerics>({ 19 | // name: "Mitko", 20 | // age: 12, 21 | // address: "Sofia, Bulgaria", 22 | // id: 1, 23 | // }); 24 | 25 | // const y = getTestGenerics>({ 26 | // name: "Mitko", 27 | // age: 12, 28 | // address: "Sofia, Bulgaria", 29 | // id: "xyz123", 30 | // }); 31 | 32 | // const generateAndAttachId = (obj: T) => { 33 | // const objId = Math.random(); 34 | // return { ...obj, id: objId }; 35 | // }; 36 | 37 | // type PersonObjectDetails = { 38 | // name: string; 39 | // age: number; 40 | // city: string; 41 | // }; 42 | 43 | // const person: PersonObjectDetails = { name: "Mitko", age: 21, city: "Lovech" }; 44 | // const personWithId = generateAndAttachId(person); 45 | // console.log(personWithId); 46 | 47 | // type AnimalObjectDetails = { 48 | // legsCount: number; 49 | // furColor: string; 50 | // name: string; 51 | // }; 52 | 53 | // const animal: AnimalObjectDetails = { 54 | // legsCount: 4, 55 | // furColor: "blonde", 56 | // name: "fluffy", 57 | // }; 58 | // const animalWithId = generateAndAttachId(animal); 59 | // console.log(animalWithId); 60 | 61 | // interface DocumentObject { 62 | // id: number; 63 | // name: string; 64 | // data: T; 65 | // } 66 | 67 | // const doc1: DocumentObject<{ name: string }[]> = { 68 | // id: 1, 69 | // name: "flowers", 70 | // data: [{ name: "flower1" }, { name: "flower2" }], 71 | // }; 72 | 73 | // const doc2: DocumentObject<{ name: string; age: number; address: string }> = { 74 | // id: 2, 75 | // name: "person", 76 | // data: { name: "Pesho", age: 12, address: "Bulgaira" }, 77 | // }; 78 | 79 | // const doc3: DocumentObject = { 80 | // id: 3, 81 | // name: "testr", 82 | // data: 1, 83 | // }; 84 | 85 | // function echo(arg: T): T { 86 | // console.log(typeof arg); 87 | 88 | // return arg; 89 | // } 90 | 91 | // console.log("-----------------"); 92 | // echo(1); 93 | // echo("string"); 94 | // echo(true); 95 | // echo([1, 2, 3]); 96 | 97 | // const takeLast = (array: T[]): T => { 98 | // return array[array.length - 1]; 99 | // }; 100 | 101 | // console.log(takeLast([1, 2, 3, 4])); 102 | // console.log(takeLast(["a", "b", "c", "d"])); 103 | // console.log(takeLast([true, false, true])); 104 | // console.log(takeLast([{ a: 1 }, { a: 2 }, { a: 3 }])); 105 | 106 | // const obj = { a: 1, b: 2, c: 3 }; 107 | // console.log(Object.entries(obj)); 108 | 109 | // const makeTuples = (a: T, b: Z): (T | Z)[] => { 110 | // return [a, b]; 111 | // }; 112 | 113 | // console.log(makeTuples("a", true)); 114 | // console.log(makeTuples(1, "true")); 115 | 116 | // type GenericConstructor = { 117 | // (arg1: T, arg2: V): [T, V]; 118 | // }; 119 | 120 | // const generateFn: GenericConstructor = ( 121 | // arg1: T, 122 | // arg2: V 123 | // ) => { 124 | // return [arg1, arg2]; 125 | // }; 126 | 127 | // const output = generateFn("Hello", 55); 128 | // console.log(output); 129 | 130 | class Collection { 131 | data: T[]; 132 | 133 | constructor(...elements: T[]) { 134 | this.data = elements; 135 | } 136 | 137 | addElement(el: T) { 138 | this.data.push(el); 139 | } 140 | 141 | removeElemet(el: T) { 142 | const index = this.data.indexOf(el); 143 | if (index > -1) { 144 | this.data.splice(index, 1); 145 | } 146 | } 147 | } 148 | 149 | // const numberCollection = new Collection(1, 2, 3, 4); 150 | // console.log(numberCollection.data); 151 | // numberCollection.addElement(99); 152 | // numberCollection.removeElemet(2); 153 | // console.log(numberCollection.data); 154 | 155 | // const stringCollection = new Collection("a", "b", "c", "d"); 156 | // console.log(stringCollection.data); 157 | // stringCollection.addElement("Pokemon"); 158 | // stringCollection.removeElemet("c"); 159 | // console.log(stringCollection.data); 160 | 161 | // class Test { 162 | // first: F; 163 | // second: S; 164 | 165 | // constructor(first: F, second: S) { 166 | // this.first = first; 167 | // this.second = second; 168 | // } 169 | 170 | // getConcatinatedArguments() { 171 | // return `My first param: ${this.first} and my second param: ${this.second}`; 172 | // } 173 | // } 174 | 175 | // const test1 = new Test(1, "Gosho"); 176 | // console.log(test1.getConcatinatedArguments()); 177 | // const test2 = new Test("Zebra", { success: true }); 178 | // console.log(test2.getConcatinatedArguments()); 179 | 180 | // const person = { 181 | // age: 33, 182 | // addres: "Sofia, Bulgaria", 183 | // firstName: "Pesho", 184 | // lastName: "Ivanov", 185 | // }; 186 | 187 | // interface FullName { 188 | // firstName: string; 189 | // lastName: string; 190 | // } 191 | 192 | // function fullName(obj: T) { 193 | // return `The full name of the user is ${obj.firstName} ${obj.lastName}!`; 194 | // } 195 | 196 | // console.log(fullName(person)); 197 | 198 | // class BankAccount { 199 | // private static id: number; 200 | // private balance: number = 0; 201 | // private interestRate: number = 0.02; 202 | 203 | // constructor() { 204 | // BankAccount.id += 1; 205 | // } 206 | 207 | // public setInterestRate(interestRate: number) { 208 | // this.interestRate = interestRate; 209 | // } 210 | 211 | // public getInterest(id: number, years: number) { 212 | // return this.interestRate; 213 | // } 214 | 215 | // public deposit(id: number, amount: number) { 216 | // this.balance = amount; 217 | // } 218 | // } 219 | 220 | // to have for sure -> {age: number} 221 | const getSmth = (obj: T) => { 222 | return obj; 223 | }; 224 | 225 | getSmth({ username: "123", password: "123", a: 1, b: 2, c: 3 }); 226 | -------------------------------------------------------------------------------- /TypeScript-OOP/dist/app.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // PROCEDURAL PROGRAMMING 3 | // const baseSalary = 30000; 4 | // const overtime = 10; 5 | // function getWage(baseSalary: number, overtime: number) { 6 | // return baseSalary + overtime * 1.5; 7 | // } 8 | // console.log(getWage(baseSalary, overtime)); 9 | // // OBJECT-ORIENTED WAY 10 | // const employee = { 11 | // baseSalary: 30000, 12 | // overtime: 10, 13 | // // Unlce Bob -> the best function is the function with no parameters 14 | // getWage: function (): number { 15 | // return this.baseSalary + this.overtime * 1.5; 16 | // }, 17 | // }; 18 | // console.log(employee.getWage()); 19 | // const car = { 20 | // speedLimit: 120, 21 | // suspension: "air", 22 | // color: "green", 23 | // getColorSuspensionAndLimit: function () { 24 | // return this.color + this.speedLimit + this.suspension; 25 | // }, 26 | // }; 27 | // interface Details { 28 | // getDetails: () => void; 29 | // } 30 | // Encapsulation 31 | // class Person implements Details { 32 | // // Abstraction 33 | // private eyeColor: string; 34 | // private skinColor: string; 35 | // constructor(eyeColor: string, skinColor: string) { 36 | // this.eyeColor = eyeColor; 37 | // this.skinColor = skinColor; 38 | // } 39 | // public getDetails(): void { 40 | // console.log( 41 | // `Hello, my eyes are ${this.eyeColor} and skin is ${this.skinColor}` 42 | // ); 43 | // } 44 | // } 45 | // class Computer implements Details { 46 | // private color: string; 47 | // constructor(color: string) { 48 | // this.color = color; 49 | // } 50 | // public getDetails(): void { 51 | // console.log(`Hello, this computer is ${this.color} color!`); 52 | // } 53 | // } 54 | // const person = new Person("grey", "grey"); 55 | // person.getDetails(); 56 | // const comp = new Computer("red"); 57 | // comp.getDetails(); 58 | /** SOLID */ 59 | // // Single Responsibility 60 | // class StudentDemo { 61 | // studentId: number; 62 | // firstName: string; 63 | // lastName: string; 64 | // constructor(studentId: number, firstName: string, lastName: string) { 65 | // this.studentId = studentId; 66 | // this.firstName = firstName; 67 | // this.lastName = lastName; 68 | // } 69 | // save(): void { 70 | // // save student record to database 71 | // } 72 | // email(): void { 73 | // // to send email from the student 74 | // } 75 | // enrol(): void { 76 | // // to enrol student in a course 77 | // } 78 | // } 79 | // class EmailService { 80 | // // email functionalty 81 | // } 82 | // class Student { 83 | // // details for the student : id, fname, lname 84 | // } 85 | // class EnrollmentService { 86 | // // enrollment function 87 | // } 88 | // class StudentRepository { 89 | // // CRUD => Crate, Read, Update, Delete 90 | // // Repository classes -> responsible for the DB communication 91 | // } 92 | // Open-Closed 93 | // class Car { 94 | // protected color: string; 95 | // constructor(color: string) { 96 | // this.color = color; 97 | // } 98 | // getColor() { 99 | // return this.color; 100 | // } 101 | // } 102 | // class BMW extends Car { 103 | // private serialNumber: string; 104 | // constructor(color: string, serialNumber: string) { 105 | // super(color); 106 | // this.serialNumber = serialNumber; 107 | // } 108 | // getSerialDetails() { 109 | // console.log(this.color + " - " + this.serialNumber); 110 | // } 111 | // } 112 | // const moietoBMW = new BMW("red", "H@J#H@J#H@JH#Jdsds"); 113 | // console.log(moietoBMW.getColor()); 114 | // moietoBMW.getSerialDetails(); 115 | // Interface Segregation 116 | // interface Geo { 117 | // lat: string; 118 | // lng: string; 119 | // } 120 | // interface Address { 121 | // street: string; 122 | // suite: string; 123 | // city: string; 124 | // zipcode: string; 125 | // geo: Geo; 126 | // } 127 | // interface Company { 128 | // name: string; 129 | // catchPhrase: string; 130 | // bs: string; 131 | // } 132 | // interface PersonDetails { 133 | // id: number; 134 | // name: string; 135 | // username: string; 136 | // email: string; 137 | // phone: string; 138 | // } 139 | // interface User { 140 | // details: PersonDetails; 141 | // address: Address; 142 | // website: string; 143 | // company: Company; 144 | // } 145 | // class Person implements PersonDetails { 146 | // id: number = 0; 147 | // name: string = ""; 148 | // username: string = ""; 149 | // email: string = ""; 150 | // phone: string = ""; 151 | // } 152 | // // Dependency Inversion Principle 153 | // class Wallet { 154 | // balance: number; 155 | // constructor(balance: number) { 156 | // this.balance = balance; 157 | // } 158 | // } 159 | // class User { 160 | // wallet: Wallet; 161 | // firsName: string; 162 | // constructor(firsName: string, wallet: Wallet) { 163 | // this.firsName = firsName; 164 | // this.wallet = wallet; 165 | // } 166 | // getWalletBalance() { 167 | // return `${this.firsName} has ${this.wallet.balance} in his pocket!`; 168 | // } 169 | // } 170 | // const ivansWallet = new Wallet(4000); 171 | // const ivanUser = new User("Ivan", ivansWallet); 172 | // console.log(ivanUser.getWalletBalance()); 173 | // const peshoWallet = new Wallet(2000); 174 | // const peshoUser = new User("Pesho", peshoWallet); 175 | // console.log(peshoUser.getWalletBalance()); 176 | // // blueprint 177 | // class Person { 178 | // // properties 179 | // firstName: string; 180 | // age: number; 181 | // static count: number = 0; 182 | // // Object instanciation -> object creation 183 | // constructor(firstName: string, age: number) { 184 | // this.firstName = firstName; 185 | // this.age = age; 186 | // } 187 | // // methods -> behaviour 188 | // static greetinIncrementor(): number { 189 | // Person.count++; 190 | // return Person.count; 191 | // } 192 | // greeting() { 193 | // console.log( 194 | // "Hello from " + 195 | // this.firstName + 196 | // "! Greeting counter " + 197 | // Person.greetinIncrementor() 198 | // ); 199 | // } 200 | // } 201 | // // instances of a class 202 | // const personMaria = new Person("Maria", 10); 203 | // personMaria.greeting(); 204 | // const personIvan = new Person("ivan", 33); 205 | // personIvan.greeting(); 206 | // personIvan.greeting(); 207 | // const personKircho = new Person("Kircho", 13); 208 | // personKircho.greeting(); 209 | // personKircho.greeting(); 210 | // personKircho.greeting(); 211 | // GETTER AND SETTERS 212 | // class Employee { 213 | // private _firstName: string; 214 | // constructor(firstName: string) { 215 | // this._firstName = firstName; 216 | // } 217 | // public get firstName(): string { 218 | // return this._firstName; 219 | // } 220 | // public set firstName(newFirstName: string) { 221 | // if (newFirstName.length < 4) { 222 | // throw new Error("First name is less than 4 characters!"); 223 | // } 224 | // this._firstName = newFirstName; 225 | // } 226 | // } 227 | // const employeeIvan = new Employee("Ivan"); 228 | // console.log("firstName", employeeIvan.firstName); 229 | // employeeIvan.firstName = "Pokemon"; 230 | // console.log("firstName", employeeIvan.firstName); 231 | // ACCESS MODIFIERS 232 | // class Person { 233 | // protected name: string; 234 | // protected age: number; 235 | // constructor(name: string, age: number) { 236 | // this.name = name; 237 | // this.age = age; 238 | // } 239 | // protected getDetails(): void { 240 | // console.log(`My name is ${this.name} and I am ${this.age} y/o!`); 241 | // } 242 | // protected modifyAge(): void { 243 | // this.age += 1; 244 | // } 245 | // } 246 | // const mitkoPerson = new Person("Mitko", 15); 247 | // mitkoPerson.modifyAge(); 248 | // mitkoPerson.modifyAge(); 249 | // mitkoPerson.modifyAge(); 250 | // mitkoPerson.modifyAge(); 251 | // mitkoPerson.getDetails(); 252 | // // !-- Abstract classes are used only for inheritance/extension 253 | // abstract class Person { 254 | // protected name: string; 255 | // protected age: number; 256 | // constructor(name: string, age: number) { 257 | // this.name = name; 258 | // this.age = age; 259 | // } 260 | // protected getDetails(): void { 261 | // console.log(`My name is ${this.name} and I am ${this.age} y/o!`); 262 | // } 263 | // protected modifyAge(): void { 264 | // this.age += 1; 265 | // } 266 | // } 267 | // class Employee extends Person { 268 | // constructor(name: string, age: number) { 269 | // super(name, age); 270 | // } 271 | // getEmployeeDetail() { 272 | // return this.getDetails(); 273 | // } 274 | // } 275 | // const employee = new Employee("Pesho", 32); 276 | // employee.getEmployeeDetail(); 277 | // DP - Singleton -> Anti-Patterns 278 | class Singleton { 279 | constructor() { } 280 | static getInstance() { 281 | if (this.instance === null) { 282 | this.instance = new Singleton(); 283 | } 284 | return this.instance; 285 | } 286 | someMethod() { 287 | console.log("This is singleton method!"); 288 | } 289 | } 290 | Singleton.instance = null; 291 | const instance1 = Singleton.getInstance(); 292 | instance1.someMethod(); 293 | const instance2 = Singleton.getInstance(); 294 | instance2.someMethod(); 295 | const areInstancesTheSame = instance1 === instance2; 296 | console.log("areInstancesTheSame: ", areInstancesTheSame); 297 | //# sourceMappingURL=app.js.map -------------------------------------------------------------------------------- /TypeScript-OOP/src/app.ts: -------------------------------------------------------------------------------- 1 | // PROCEDURAL PROGRAMMING 2 | // const baseSalary = 30000; 3 | // const overtime = 10; 4 | 5 | // function getWage(baseSalary: number, overtime: number) { 6 | // return baseSalary + overtime * 1.5; 7 | // } 8 | 9 | // console.log(getWage(baseSalary, overtime)); 10 | 11 | // // OBJECT-ORIENTED WAY 12 | // const employee = { 13 | // baseSalary: 30000, 14 | // overtime: 10, 15 | // // Unlce Bob -> the best function is the function with no parameters 16 | // getWage: function (): number { 17 | // return this.baseSalary + this.overtime * 1.5; 18 | // }, 19 | // }; 20 | 21 | // console.log(employee.getWage()); 22 | 23 | // const car = { 24 | // speedLimit: 120, 25 | // suspension: "air", 26 | // color: "green", 27 | // getColorSuspensionAndLimit: function () { 28 | // return this.color + this.speedLimit + this.suspension; 29 | // }, 30 | // }; 31 | 32 | // interface Details { 33 | // getDetails: () => void; 34 | // } 35 | 36 | // Encapsulation 37 | // class Person implements Details { 38 | // // Abstraction 39 | // private eyeColor: string; 40 | // private skinColor: string; 41 | 42 | // constructor(eyeColor: string, skinColor: string) { 43 | // this.eyeColor = eyeColor; 44 | // this.skinColor = skinColor; 45 | // } 46 | 47 | // public getDetails(): void { 48 | // console.log( 49 | // `Hello, my eyes are ${this.eyeColor} and skin is ${this.skinColor}` 50 | // ); 51 | // } 52 | // } 53 | 54 | // class Computer implements Details { 55 | // private color: string; 56 | 57 | // constructor(color: string) { 58 | // this.color = color; 59 | // } 60 | // public getDetails(): void { 61 | // console.log(`Hello, this computer is ${this.color} color!`); 62 | // } 63 | // } 64 | 65 | // const person = new Person("grey", "grey"); 66 | // person.getDetails(); 67 | 68 | // const comp = new Computer("red"); 69 | // comp.getDetails(); 70 | 71 | /** SOLID */ 72 | 73 | // // Single Responsibility 74 | // class StudentDemo { 75 | // studentId: number; 76 | // firstName: string; 77 | // lastName: string; 78 | 79 | // constructor(studentId: number, firstName: string, lastName: string) { 80 | // this.studentId = studentId; 81 | // this.firstName = firstName; 82 | // this.lastName = lastName; 83 | // } 84 | 85 | // save(): void { 86 | // // save student record to database 87 | // } 88 | 89 | // email(): void { 90 | // // to send email from the student 91 | // } 92 | 93 | // enrol(): void { 94 | // // to enrol student in a course 95 | // } 96 | // } 97 | 98 | // class EmailService { 99 | // // email functionalty 100 | // } 101 | // class Student { 102 | // // details for the student : id, fname, lname 103 | // } 104 | // class EnrollmentService { 105 | // // enrollment function 106 | // } 107 | // class StudentRepository { 108 | // // CRUD => Crate, Read, Update, Delete 109 | // // Repository classes -> responsible for the DB communication 110 | // } 111 | 112 | // Open-Closed 113 | // class Car { 114 | // protected color: string; 115 | 116 | // constructor(color: string) { 117 | // this.color = color; 118 | // } 119 | 120 | // getColor() { 121 | // return this.color; 122 | // } 123 | // } 124 | 125 | // class BMW extends Car { 126 | // private serialNumber: string; 127 | 128 | // constructor(color: string, serialNumber: string) { 129 | // super(color); 130 | // this.serialNumber = serialNumber; 131 | // } 132 | 133 | // getSerialDetails() { 134 | // console.log(this.color + " - " + this.serialNumber); 135 | // } 136 | // } 137 | 138 | // const moietoBMW = new BMW("red", "H@J#H@J#H@JH#Jdsds"); 139 | // console.log(moietoBMW.getColor()); 140 | // moietoBMW.getSerialDetails(); 141 | 142 | // Interface Segregation 143 | // interface Geo { 144 | // lat: string; 145 | // lng: string; 146 | // } 147 | 148 | // interface Address { 149 | // street: string; 150 | // suite: string; 151 | // city: string; 152 | // zipcode: string; 153 | // geo: Geo; 154 | // } 155 | 156 | // interface Company { 157 | // name: string; 158 | // catchPhrase: string; 159 | // bs: string; 160 | // } 161 | 162 | // interface PersonDetails { 163 | // id: number; 164 | // name: string; 165 | // username: string; 166 | // email: string; 167 | // phone: string; 168 | // } 169 | 170 | // interface User { 171 | // details: PersonDetails; 172 | // address: Address; 173 | // website: string; 174 | // company: Company; 175 | // } 176 | 177 | // class Person implements PersonDetails { 178 | // id: number = 0; 179 | // name: string = ""; 180 | // username: string = ""; 181 | // email: string = ""; 182 | // phone: string = ""; 183 | // } 184 | 185 | // // Dependency Inversion Principle 186 | // class Wallet { 187 | // balance: number; 188 | 189 | // constructor(balance: number) { 190 | // this.balance = balance; 191 | // } 192 | // } 193 | 194 | // class User { 195 | // wallet: Wallet; 196 | // firsName: string; 197 | 198 | // constructor(firsName: string, wallet: Wallet) { 199 | // this.firsName = firsName; 200 | // this.wallet = wallet; 201 | // } 202 | 203 | // getWalletBalance() { 204 | // return `${this.firsName} has ${this.wallet.balance} in his pocket!`; 205 | // } 206 | // } 207 | 208 | // const ivansWallet = new Wallet(4000); 209 | // const ivanUser = new User("Ivan", ivansWallet); 210 | // console.log(ivanUser.getWalletBalance()); 211 | 212 | // const peshoWallet = new Wallet(2000); 213 | // const peshoUser = new User("Pesho", peshoWallet); 214 | // console.log(peshoUser.getWalletBalance()); 215 | 216 | // // blueprint 217 | // class Person { 218 | // // properties 219 | // firstName: string; 220 | // age: number; 221 | // static count: number = 0; 222 | 223 | // // Object instanciation -> object creation 224 | // constructor(firstName: string, age: number) { 225 | // this.firstName = firstName; 226 | // this.age = age; 227 | // } 228 | 229 | // // methods -> behaviour 230 | // static greetinIncrementor(): number { 231 | // Person.count++; 232 | // return Person.count; 233 | // } 234 | // greeting() { 235 | // console.log( 236 | // "Hello from " + 237 | // this.firstName + 238 | // "! Greeting counter " + 239 | // Person.greetinIncrementor() 240 | // ); 241 | // } 242 | // } 243 | 244 | // // instances of a class 245 | // const personMaria = new Person("Maria", 10); 246 | // personMaria.greeting(); 247 | 248 | // const personIvan = new Person("ivan", 33); 249 | // personIvan.greeting(); 250 | // personIvan.greeting(); 251 | 252 | // const personKircho = new Person("Kircho", 13); 253 | // personKircho.greeting(); 254 | // personKircho.greeting(); 255 | // personKircho.greeting(); 256 | 257 | // GETTER AND SETTERS 258 | // class Employee { 259 | // private _firstName: string; 260 | 261 | // constructor(firstName: string) { 262 | // this._firstName = firstName; 263 | // } 264 | 265 | // public get firstName(): string { 266 | // return this._firstName; 267 | // } 268 | 269 | // public set firstName(newFirstName: string) { 270 | // if (newFirstName.length < 4) { 271 | // throw new Error("First name is less than 4 characters!"); 272 | // } 273 | 274 | // this._firstName = newFirstName; 275 | // } 276 | // } 277 | 278 | // const employeeIvan = new Employee("Ivan"); 279 | // console.log("firstName", employeeIvan.firstName); 280 | // employeeIvan.firstName = "Pokemon"; 281 | // console.log("firstName", employeeIvan.firstName); 282 | 283 | // ACCESS MODIFIERS 284 | // class Person { 285 | // protected name: string; 286 | // protected age: number; 287 | 288 | // constructor(name: string, age: number) { 289 | // this.name = name; 290 | // this.age = age; 291 | // } 292 | 293 | // protected getDetails(): void { 294 | // console.log(`My name is ${this.name} and I am ${this.age} y/o!`); 295 | // } 296 | 297 | // protected modifyAge(): void { 298 | // this.age += 1; 299 | // } 300 | // } 301 | 302 | // const mitkoPerson = new Person("Mitko", 15); 303 | // mitkoPerson.modifyAge(); 304 | // mitkoPerson.modifyAge(); 305 | // mitkoPerson.modifyAge(); 306 | // mitkoPerson.modifyAge(); 307 | // mitkoPerson.getDetails(); 308 | 309 | // // !-- Abstract classes are used only for inheritance/extension 310 | // abstract class Person { 311 | // protected name: string; 312 | // protected age: number; 313 | 314 | // constructor(name: string, age: number) { 315 | // this.name = name; 316 | // this.age = age; 317 | // } 318 | 319 | // protected getDetails(): void { 320 | // console.log(`My name is ${this.name} and I am ${this.age} y/o!`); 321 | // } 322 | 323 | // protected modifyAge(): void { 324 | // this.age += 1; 325 | // } 326 | // } 327 | 328 | // class Employee extends Person { 329 | // constructor(name: string, age: number) { 330 | // super(name, age); 331 | // } 332 | 333 | // getEmployeeDetail() { 334 | // return this.getDetails(); 335 | // } 336 | // } 337 | 338 | // const employee = new Employee("Pesho", 32); 339 | // employee.getEmployeeDetail(); 340 | 341 | // DP - Singleton -> Anti-Patterns 342 | 343 | // class Singleton { 344 | // private static instance: Singleton | null = null; 345 | 346 | // private constructor() {} 347 | 348 | // public static getInstance(): Singleton { 349 | // if (this.instance === null) { 350 | // this.instance = new Singleton(); 351 | // } 352 | 353 | // return this.instance; 354 | // } 355 | 356 | // public someMethod(): void { 357 | // console.log("This is singleton method!"); 358 | // } 359 | // } 360 | 361 | // const instance1 = Singleton.getInstance(); 362 | // instance1.someMethod(); 363 | 364 | // const instance2 = Singleton.getInstance(); 365 | // instance2.someMethod(); 366 | 367 | // const areInstancesTheSame = instance1 === instance2; 368 | // console.log("areInstancesTheSame: ", areInstancesTheSame); 369 | 370 | // Composition 371 | // Component 1 372 | class Engine { 373 | start() { 374 | console.log("Engine started"); 375 | } 376 | } 377 | 378 | // Component 2 379 | class Wheels { 380 | roll() { 381 | console.log("Wheels rolling"); 382 | } 383 | } 384 | 385 | // Component 3 386 | class GPS { 387 | navigate(destination: string) { 388 | console.log(`Navigating to ${destination}`); 389 | } 390 | } 391 | 392 | // Car class composed of Engine, Wheels, and GPS 393 | class Car { 394 | private engine: Engine; 395 | private wheels: Wheels; 396 | private gps: GPS; 397 | 398 | constructor(engine: Engine, wheels: Wheels, gps: GPS) { 399 | this.engine = engine; 400 | this.wheels = wheels; 401 | this.gps = gps; 402 | } 403 | 404 | drive(destination: string) { 405 | this.engine.start(); 406 | this.wheels.roll(); 407 | this.gps.navigate(destination); 408 | } 409 | } 410 | 411 | // Example usage 412 | const myEngine = new Engine(); 413 | const myWheels = new Wheels(); 414 | const myGps = new GPS(); 415 | 416 | const myCar = new Car(myEngine, myWheels, myGps); 417 | myCar.drive("The Park"); 418 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/modules-demo/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "CommonJS" /* Specify what module code is generated. */, 29 | "rootDir": "./src" /* Specify the root folder within your source files. */, 30 | // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ 39 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ 40 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ 41 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ 42 | // "resolveJsonModule": true, /* Enable importing .json files. */ 43 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ 44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 45 | 46 | /* JavaScript Support */ 47 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 48 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 50 | 51 | /* Emit */ 52 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 53 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 55 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 56 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 57 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 58 | "outDir": "./dist" /* Specify an output folder for all emitted files. */, 59 | // "removeComments": true, /* Disable emitting comments. */ 60 | // "noEmit": true, /* Disable emitting files from a compilation. */ 61 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 62 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 63 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 64 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 65 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 68 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 75 | 76 | /* Interop Constraints */ 77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 78 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ 79 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 80 | "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, 81 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 82 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, 83 | 84 | /* Type Checking */ 85 | "strict": true /* Enable all strict type-checking options. */, 86 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 87 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 88 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 89 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 90 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 91 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 92 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 93 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 94 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 95 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 96 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 97 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 98 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 99 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 100 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 101 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 102 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 103 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 104 | 105 | /* Completeness */ 106 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 107 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Namespaces-and-Modules/namespaces-demo/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "commonjs", /* Specify what module code is generated. */ 29 | // "rootDir": "./", /* Specify the root folder within your source files. */ 30 | // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ 39 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ 40 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ 41 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ 42 | // "resolveJsonModule": true, /* Enable importing .json files. */ 43 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ 44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 45 | 46 | /* JavaScript Support */ 47 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 48 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 50 | 51 | /* Emit */ 52 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 53 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 55 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 56 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 57 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 58 | // "outDir": "./", /* Specify an output folder for all emitted files. */ 59 | // "removeComments": true, /* Disable emitting comments. */ 60 | // "noEmit": true, /* Disable emitting files from a compilation. */ 61 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 62 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 63 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 64 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 65 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 68 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 75 | 76 | /* Interop Constraints */ 77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 78 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ 79 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 80 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 81 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 82 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 83 | 84 | /* Type Checking */ 85 | "strict": true, /* Enable all strict type-checking options. */ 86 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 87 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 88 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 89 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 90 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 91 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 92 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 93 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 94 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 95 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 96 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 97 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 98 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 99 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 100 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 101 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 102 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 103 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 104 | 105 | /* Completeness */ 106 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 107 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 108 | } 109 | } 110 | --------------------------------------------------------------------------------