Skip to content

Commit 2b037e5

Browse files
bootstrap things
Signed-off-by: ivan katliarchuk <[email protected]>
1 parent d0cbadb commit 2b037e5

File tree

8 files changed

+238
-1
lines changed

8 files changed

+238
-1
lines changed

2-understand/type-casting/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
],
1414
"license": "ISC",
1515
"devDependencies": {
16-
"lite-server": "^2.5.4"
1716
},
1817
"dependencies": {
1918
"typescript": "^5.7.2"

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ validate: ## Validate files with pre-commit hooks
1818
cleanup: ## Cleanup folders
1919
@find . -type d -name "node_modules" -prune -exec rm -rf {} \;
2020
# @find . -type f -name "*.lock" -prune -exec rm {} \;
21+
22+
DIRECTORY := with-tests/eks-addons
23+
24+
run: ## Run it
25+
@scripts/run.sh $(DIRECTORY)
26+
27+
install: ## Install dependencies
28+
@scripts/install.sh $(DIRECTORY)

scripts/install.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
if [ $# -eq 0 ]
4+
then
5+
echo -e "You need to specify the target directory.\n"
6+
echo -e "Usage:"
7+
echo -e "\t$0 <directory>"
8+
exit 1
9+
else
10+
directory=$1
11+
fi
12+
13+
echo "in: $directory"
14+
15+
cd $directory
16+
17+
npm install

scripts/run.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
if [ $# -eq 0 ]
4+
then
5+
echo -e "You need to specify the target directory.\n"
6+
echo -e "Usage:"
7+
echo -e "\t$0 <directory>"
8+
exit 1
9+
else
10+
directory=$1
11+
fi
12+
13+
echo "in: $directory"
14+
15+
cd $directory
16+
17+
deno run src/app.ts

with-tests/eks-addons/package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "understanding-typescript",
3+
"version": "1.0.0",
4+
"description": "Understanding TypeScript Course Setup",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "lite-server"
9+
},
10+
"keywords": [
11+
"typescript",
12+
"course"
13+
],
14+
"license": "ISC",
15+
"devDependencies": {
16+
},
17+
"dependencies": {
18+
"typescript": "^5.7.2"
19+
}
20+
}

with-tests/eks-addons/src/app.ts

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
type Admin = {
2+
name: string;
3+
privileges: string[];
4+
};
5+
6+
type Employee = {
7+
name: string;
8+
startDate: Date;
9+
};
10+
11+
// interface ElevatedEmployee extends Employee, Admin {}
12+
13+
type ElevatedEmployee = Admin & Employee;
14+
15+
const e1: ElevatedEmployee = {
16+
name: 'Max',
17+
privileges: ['create-server'],
18+
startDate: new Date()
19+
};
20+
21+
type Combinable = string | number;
22+
type Numeric = number | boolean;
23+
24+
type Universal = Combinable & Numeric;
25+
26+
function add(a: Combinable, b: Combinable) {
27+
if (typeof a === 'string' || typeof b === 'string') {
28+
return a.toString() + b.toString();
29+
}
30+
return a + b;
31+
}
32+
33+
type UnknownEmployee = Employee | Admin;
34+
35+
function printEmployeeInformation(emp: UnknownEmployee) {
36+
console.log('Name: ' + emp.name);
37+
if ('privileges' in emp) {
38+
console.log('Privileges: ' + emp.privileges);
39+
}
40+
if ('startDate' in emp) {
41+
console.log('Start Date: ' + emp.startDate);
42+
}
43+
}
44+
45+
printEmployeeInformation({ name: 'Manu', startDate: new Date() });
46+
47+
class Car {
48+
drive() {
49+
console.log('Driving...');
50+
}
51+
}
52+
53+
class Truck {
54+
drive() {
55+
console.log('Driving a truck...');
56+
}
57+
58+
loadCargo(amount: number) {
59+
console.log('Loading cargo ...' + amount);
60+
}
61+
}
62+
63+
type Vehicle = Car | Truck;
64+
65+
const v1 = new Car();
66+
const v2 = new Truck();
67+
68+
function useVehicle(vehicle: Vehicle) {
69+
vehicle.drive();
70+
if (vehicle instanceof Truck) {
71+
vehicle.loadCargo(1000);
72+
}
73+
}
74+
75+
useVehicle(v1);
76+
useVehicle(v2);
77+
78+
interface Bird {
79+
type: 'bird';
80+
flyingSpeed: number;
81+
}
82+
83+
interface Horse {
84+
type: 'horse';
85+
runningSpeed: number;
86+
}
87+
88+
type Animal = Bird | Horse;
89+
90+
function moveAnimal(animal: Animal) {
91+
let speed;
92+
switch (animal.type) {
93+
case 'bird':
94+
speed = animal.flyingSpeed;
95+
break;
96+
case 'horse':
97+
speed = animal.runningSpeed;
98+
}
99+
console.log('Moving at speed: ' + speed);
100+
}
101+
102+
moveAnimal({type: 'bird', flyingSpeed: 10});
103+

with-tests/eks-addons/tsconfig.json

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
5+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
"lib": [
7+
"dom",
8+
"es6",
9+
"dom.iterable",
10+
"scripthost"
11+
], /* Specify library files to be included in the compilation. */
12+
// "allowJs": true, /* Allow javascript files to be compiled. */
13+
// "checkJs": true, /* Report errors in .js files. */
14+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
15+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
16+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
17+
"sourceMap": true, /* Generates corresponding '.map' file. */
18+
// "outFile": "./", /* Concatenate and emit output to single file. */
19+
"outDir": "./dist", /* Redirect output structure to the directory. */
20+
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
21+
// "composite": true, /* Enable project compilation */
22+
"removeComments": true, /* Do not emit comments to output. */
23+
// "noEmit": true, /* Do not emit outputs. */
24+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
25+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
26+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
27+
"noEmitOnError": true,
28+
29+
/* Strict Type-Checking Options */
30+
"strict": true, /* Enable all strict type-checking options. */
31+
// "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
32+
// "strictNullChecks": true, /* Enable strict null checks. */
33+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
34+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
35+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
36+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
37+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
38+
39+
/* Additional Checks */
40+
"noUnusedLocals": true, /* Report errors on unused locals. */
41+
"noUnusedParameters": true, /* Report errors on unused parameters. */
42+
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
43+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
44+
45+
/* Module Resolution Options */
46+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
47+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
48+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
49+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
50+
// "typeRoots": [], /* List of folders to include type definitions from. */
51+
// "types": [], /* Type declaration files to be included in compilation. */
52+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
53+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
54+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
55+
56+
/* Source Map Options */
57+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
58+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
59+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
60+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
61+
62+
/* Experimental Options */
63+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
64+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
65+
},
66+
"exclude": [
67+
"node_modules" // would be the default
68+
]
69+
}

yarn.lock

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+

0 commit comments

Comments
 (0)