mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(challenge15): function overload
This commit is contained in:
36
apps/overload/.eslintrc.json
Normal file
36
apps/overload/.eslintrc.json
Normal file
@@ -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": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
31
apps/overload/README.md
Normal file
31
apps/overload/README.md
Normal file
@@ -0,0 +1,31 @@
|
||||
<h1>Function overload</h1>
|
||||
|
||||
> 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.
|
||||
|
||||
<a href="https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A15+label%3Aanswer"><img src="https://img.shields.io/badge/-Solutions-green" alt="overload"/></a>
|
||||
|
||||
<!-- TODO: uncomment when done late -->
|
||||
<!-- <a href='https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A15+label%3A"answer+author"'><img src="https://img.shields.io/badge/-Author solution-important" alt="overload solution author"/></a>
|
||||
<a href="{Blog post url}" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/-Blog post explanation-blue" alt="overload blog article"/></a> -->
|
||||
|
||||
_You can ask any question on_ <a href="https://twitter.com/laforge_toma" target="_blank" rel="noopener noreferrer"><img src="./../../logo/twitter.svg" height=20px alt="twitter"/></a>
|
||||
76
apps/overload/project.json
Normal file
76
apps/overload/project.json
Normal file
@@ -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": []
|
||||
}
|
||||
14
apps/overload/src/app/app.component.ts
Normal file
14
apps/overload/src/app/app.component.ts
Normal file
@@ -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');
|
||||
}
|
||||
55
apps/overload/src/app/teacher.utils.ts
Normal file
55
apps/overload/src/app/teacher.utils.ts
Normal file
@@ -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 };
|
||||
}
|
||||
}
|
||||
0
apps/overload/src/assets/.gitkeep
Normal file
0
apps/overload/src/assets/.gitkeep
Normal file
BIN
apps/overload/src/favicon.ico
Normal file
BIN
apps/overload/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
13
apps/overload/src/index.html
Normal file
13
apps/overload/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Overload</title>
|
||||
<base href="/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
4
apps/overload/src/main.ts
Normal file
4
apps/overload/src/main.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app/app.component';
|
||||
|
||||
bootstrapApplication(AppComponent).catch((err) => console.error(err));
|
||||
1
apps/overload/src/styles.scss
Normal file
1
apps/overload/src/styles.scss
Normal file
@@ -0,0 +1 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
10
apps/overload/tsconfig.app.json
Normal file
10
apps/overload/tsconfig.app.json
Normal file
@@ -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"]
|
||||
}
|
||||
7
apps/overload/tsconfig.editor.json
Normal file
7
apps/overload/tsconfig.editor.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src/**/*.ts"],
|
||||
"compilerOptions": {
|
||||
"types": []
|
||||
}
|
||||
}
|
||||
29
apps/overload/tsconfig.json
Normal file
29
apps/overload/tsconfig.json
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user