diff --git a/apps/overload/.eslintrc.json b/apps/overload/.eslintrc.json new file mode 100644 index 0000000..c34c7dd --- /dev/null +++ b/apps/overload/.eslintrc.json @@ -0,0 +1,36 @@ +{ + "extends": ["../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts"], + "rules": { + "@angular-eslint/directive-selector": [ + "error", + { + "type": "attribute", + "prefix": "app", + "style": "camelCase" + } + ], + "@angular-eslint/component-selector": [ + "error", + { + "type": "element", + "prefix": "app", + "style": "kebab-case" + } + ] + }, + "extends": [ + "plugin:@nrwl/nx/angular", + "plugin:@angular-eslint/template/process-inline-templates" + ] + }, + { + "files": ["*.html"], + "extends": ["plugin:@nrwl/nx/angular-template"], + "rules": {} + } + ] +} diff --git a/apps/overload/README.md b/apps/overload/README.md new file mode 100644 index 0000000..9696340 --- /dev/null +++ b/apps/overload/README.md @@ -0,0 +1,31 @@ +

Function overload

+ +> Author: Thomas Laforge + +### Information + +### Statement + +### Step 1 + +### Step 2 + +### Constraints: + +### Submitting your work + +1. Fork the project +2. clone it +3. npm install +4. **`npx nx serve overload`** +5. _...work on it_ +6. Commit your work +7. Submit a PR with a title beginning with **Answer:15** that I will review and other dev can review. + +overload + + + + +_You can ask any question on_ twitter diff --git a/apps/overload/project.json b/apps/overload/project.json new file mode 100644 index 0000000..5fa620d --- /dev/null +++ b/apps/overload/project.json @@ -0,0 +1,76 @@ +{ + "name": "overload", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "sourceRoot": "apps/overload/src", + "prefix": "app", + "targets": { + "build": { + "executor": "@angular-devkit/build-angular:browser", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/apps/overload", + "index": "apps/overload/src/index.html", + "main": "apps/overload/src/main.ts", + "polyfills": ["zone.js"], + "tsConfig": "apps/overload/tsconfig.app.json", + "inlineStyleLanguage": "scss", + "assets": ["apps/overload/src/favicon.ico", "apps/overload/src/assets"], + "styles": ["apps/overload/src/styles.scss"], + "scripts": [] + }, + "configurations": { + "production": { + "budgets": [ + { + "type": "initial", + "maximumWarning": "500kb", + "maximumError": "1mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "2kb", + "maximumError": "4kb" + } + ], + "outputHashing": "all" + }, + "development": { + "buildOptimizer": false, + "optimization": false, + "vendorChunk": true, + "extractLicenses": false, + "sourceMap": true, + "namedChunks": true + } + }, + "defaultConfiguration": "production" + }, + "serve": { + "executor": "@angular-devkit/build-angular:dev-server", + "configurations": { + "production": { + "browserTarget": "overload:build:production" + }, + "development": { + "browserTarget": "overload:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "executor": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "overload:build" + } + }, + "lint": { + "executor": "@nrwl/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["apps/overload/**/*.ts", "apps/overload/**/*.html"] + } + } + }, + "tags": [] +} diff --git a/apps/overload/src/app/app.component.ts b/apps/overload/src/app/app.component.ts new file mode 100644 index 0000000..e4821fb --- /dev/null +++ b/apps/overload/src/app/app.component.ts @@ -0,0 +1,14 @@ +import { Component } from '@angular/core'; +import { createVehicle } from './teacher.utils'; + +@Component({ + standalone: true, + selector: 'app-root', + template: ``, +}) +export class AppComponent { + car = createVehicle('car', 'diesel'); + bus = createVehicle('bus', undefined, 20); + boat = createVehicle('boat', undefined, 300, true); + bicycle = createVehicle('bicycle'); +} diff --git a/apps/overload/src/app/teacher.utils.ts b/apps/overload/src/app/teacher.utils.ts new file mode 100644 index 0000000..ce55386 --- /dev/null +++ b/apps/overload/src/app/teacher.utils.ts @@ -0,0 +1,55 @@ +type VehicleType = 'bus' | 'car' | 'moto' | 'bicycle' | 'boat'; +type Fuel = 'diesel' | 'petrol' | 'electric'; + +interface Bicycle { + type: 'bicycle'; +} + +interface Car { + fuel: Fuel; + type: 'car'; +} + +interface Moto { + fuel: Fuel; + type: 'moto'; +} + +interface Bus { + capacity: number; + isPublicTransport: boolean; + type: 'bus'; +} + +interface Boat { + capacity: number; + type: 'boat'; +} + +type Vehicle = Bicycle | Car | Moto | Bus | Boat; + +export function createVehicle( + type: VehicleType, + fuel?: Fuel, + capacity?: number, + isPublicTransport?: boolean +): Vehicle { + switch (type) { + case 'bicycle': + return { type }; + case 'car': + case 'moto': + if (!fuel) throw new Error(`fuel property is missing for type ${type}`); + return { fuel, type }; + case 'boat': + if (!capacity) + throw new Error(`capacity property is missing for type boat`); + return { capacity, type }; + case 'bus': + if (!capacity) + throw new Error(`capacity property is missing for type bus`); + if (!isPublicTransport) + throw new Error(`isPublicTransport property is missing for type bus`); + return { capacity, isPublicTransport, type }; + } +} diff --git a/apps/overload/src/assets/.gitkeep b/apps/overload/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/overload/src/favicon.ico b/apps/overload/src/favicon.ico new file mode 100644 index 0000000..317ebcb Binary files /dev/null and b/apps/overload/src/favicon.ico differ diff --git a/apps/overload/src/index.html b/apps/overload/src/index.html new file mode 100644 index 0000000..e501c90 --- /dev/null +++ b/apps/overload/src/index.html @@ -0,0 +1,13 @@ + + + + + Overload + + + + + + + + diff --git a/apps/overload/src/main.ts b/apps/overload/src/main.ts new file mode 100644 index 0000000..31c5da4 --- /dev/null +++ b/apps/overload/src/main.ts @@ -0,0 +1,4 @@ +import { bootstrapApplication } from '@angular/platform-browser'; +import { AppComponent } from './app/app.component'; + +bootstrapApplication(AppComponent).catch((err) => console.error(err)); diff --git a/apps/overload/src/styles.scss b/apps/overload/src/styles.scss new file mode 100644 index 0000000..90d4ee0 --- /dev/null +++ b/apps/overload/src/styles.scss @@ -0,0 +1 @@ +/* You can add global styles to this file, and also import other style files */ diff --git a/apps/overload/tsconfig.app.json b/apps/overload/tsconfig.app.json new file mode 100644 index 0000000..fff4a41 --- /dev/null +++ b/apps/overload/tsconfig.app.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": [] + }, + "files": ["src/main.ts"], + "include": ["src/**/*.d.ts"], + "exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"] +} diff --git a/apps/overload/tsconfig.editor.json b/apps/overload/tsconfig.editor.json new file mode 100644 index 0000000..4ee6393 --- /dev/null +++ b/apps/overload/tsconfig.editor.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*.ts"], + "compilerOptions": { + "types": [] + } +} diff --git a/apps/overload/tsconfig.json b/apps/overload/tsconfig.json new file mode 100644 index 0000000..0731542 --- /dev/null +++ b/apps/overload/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "target": "es2022", + "useDefineForClassFields": false, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.app.json" + }, + { + "path": "./tsconfig.editor.json" + } + ], + "extends": "../../tsconfig.base.json", + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +}