feat(doc): move overload

This commit is contained in:
thomas
2023-10-18 09:47:59 +02:00
parent 64dc2046ea
commit 0fae068682
14 changed files with 25 additions and 19 deletions

View 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:@nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
]
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
}
]
}

View File

@@ -0,0 +1,13 @@
# Function Overload
> Author: Thomas Laforge
### Run Application
```bash
npx nx serve typescript-overload`
```
### Documentation and Instruction
Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/typescript/15-typescript-overload-fn/).

View File

@@ -0,0 +1,82 @@
{
"name": "typescript-overload",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "apps/typescript/overload/src",
"prefix": "app",
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:browser",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/typescript/overload",
"index": "apps/typescript/overload/src/index.html",
"main": "apps/typescript/overload/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/typescript/overload/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"apps/typescript/overload/src/favicon.ico",
"apps/typescript/overload/src/assets"
],
"styles": ["apps/typescript/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": "typescript-overload:build:production"
},
"development": {
"browserTarget": "typescript-overload:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "typescript-overload:build"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"apps/typescript/overload/**/*.ts",
"apps/typescript/overload/**/*.html"
]
}
}
},
"tags": []
}

View File

@@ -0,0 +1,15 @@
import { Component } from '@angular/core';
import { createVehicle } from './vehicle.utils';
@Component({
standalone: true,
selector: 'app-root',
template: ``,
})
export class AppComponent {
car = createVehicle('car', 'diesel');
moto = createVehicle('moto', 'diesel');
bus = createVehicle('bus', undefined, 20);
boat = createVehicle('boat', undefined, 300, true);
bicycle = createVehicle('bicycle');
}

View 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 };
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View 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>

View File

@@ -0,0 +1,4 @@
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

View File

@@ -0,0 +1 @@
/* You can add global styles to this file, and also import other style files */

View 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"]
}

View File

@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"],
"compilerOptions": {
"types": []
}
}

View 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
}
}