Skip to content

Commit 1f4007c

Browse files
refresh repo
Signed-off-by: ivan katliarchuk <[email protected]>
1 parent e0ea5c7 commit 1f4007c

39 files changed

+7895
-1
lines changed

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18.9.0
1+
22.11.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Understanding TypeScript</title>
8+
<script src="dist/app.js" defer></script>
9+
</head>
10+
<body>
11+
<div id="app"></div>
12+
<button>Click me</button>
13+
</body>
14+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
"author": "Maximilian Schwarzmüller",
15+
"license": "ISC",
16+
"devDependencies": {
17+
"lite-server": "^2.5.4"
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
function Logger(logString: string) {
2+
console.log('LOGGER FACTORY');
3+
return function(constructor: Function) {
4+
console.log(logString);
5+
console.log(constructor);
6+
};
7+
}
8+
9+
function WithTemplate(template: string, hookId: string) {
10+
console.log('TEMPLATE FACTORY');
11+
return function<T extends { new (...args: any[]): {name: string} }>(
12+
originalConstructor: T
13+
) {
14+
return class extends originalConstructor {
15+
constructor(..._: any[]) {
16+
super();
17+
console.log('Rendering template');
18+
const hookEl = document.getElementById(hookId);
19+
if (hookEl) {
20+
hookEl.innerHTML = template;
21+
hookEl.querySelector('h1')!.textContent = this.name;
22+
}
23+
}
24+
};
25+
};
26+
}
27+
28+
// @Logger('LOGGING - PERSON')
29+
@Logger('LOGGING')
30+
@WithTemplate('<h1>My Person Object</h1>', 'app')
31+
class Person {
32+
name = 'Max';
33+
34+
constructor() {
35+
console.log('Creating person object...');
36+
}
37+
}
38+
39+
const pers = new Person();
40+
41+
console.log(pers);
42+
43+
// ---
44+
45+
function Log(target: any, propertyName: string | Symbol) {
46+
console.log('Property decorator!');
47+
console.log(target, propertyName);
48+
}
49+
50+
function Log2(target: any, name: string, descriptor: PropertyDescriptor) {
51+
console.log('Accessor decorator!');
52+
console.log(target);
53+
console.log(name);
54+
console.log(descriptor);
55+
}
56+
57+
function Log3(
58+
target: any,
59+
name: string | Symbol,
60+
descriptor: PropertyDescriptor
61+
) {
62+
console.log('Method decorator!');
63+
console.log(target);
64+
console.log(name);
65+
console.log(descriptor);
66+
}
67+
68+
function Log4(target: any, name: string | Symbol, position: number) {
69+
console.log('Parameter decorator!');
70+
console.log(target);
71+
console.log(name);
72+
console.log(position);
73+
}
74+
75+
class Product {
76+
@Log
77+
title: string;
78+
private _price: number;
79+
80+
@Log2
81+
set price(val: number) {
82+
if (val > 0) {
83+
this._price = val;
84+
} else {
85+
throw new Error('Invalid price - should be positive!');
86+
}
87+
}
88+
89+
constructor(t: string, p: number) {
90+
this.title = t;
91+
this._price = p;
92+
}
93+
94+
@Log3
95+
getPriceWithTax(@Log4 tax: number) {
96+
return this._price * (1 + tax);
97+
}
98+
}
99+
100+
const p1 = new Product('Book', 19);
101+
const p2 = new Product('Book 2', 29);
102+
103+
function Autobind(_: any, _2: string, descriptor: PropertyDescriptor) {
104+
const originalMethod = descriptor.value;
105+
const adjDescriptor: PropertyDescriptor = {
106+
configurable: true,
107+
enumerable: false,
108+
get() {
109+
const boundFn = originalMethod.bind(this);
110+
return boundFn;
111+
}
112+
};
113+
return adjDescriptor;
114+
}
115+
116+
class Printer {
117+
message = 'This works!';
118+
119+
@Autobind
120+
showMessage() {
121+
console.log(this.message);
122+
}
123+
}
124+
125+
const p = new Printer();
126+
p.showMessage();
127+
128+
const button = document.querySelector('button')!;
129+
button.addEventListener('click', p.showMessage);
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
* {
2+
box-sizing: border-box;
3+
}
4+
5+
html {
6+
font-family: sans-serif;
7+
}
8+
9+
body {
10+
margin: 0;
11+
}
12+
13+
label,
14+
input,
15+
textarea {
16+
display: block;
17+
margin: 0.5rem 0;
18+
}
19+
20+
label {
21+
font-weight: bold;
22+
}
23+
24+
input,
25+
textarea {
26+
font: inherit;
27+
padding: 0.2rem 0.4rem;
28+
width: 100%;
29+
max-width: 30rem;
30+
border: 1px solid #ccc;
31+
}
32+
33+
input:focus,
34+
textarea:focus {
35+
outline: none;
36+
background: #fff5f9;
37+
}
38+
39+
button {
40+
font: inherit;
41+
background: #ff0062;
42+
border: 1px solid #ff0062;
43+
cursor: pointer;
44+
color: white;
45+
padding: 0.75rem 1rem;
46+
}
47+
48+
button:focus {
49+
outline: none;
50+
}
51+
52+
button:hover,
53+
button:active {
54+
background: #a80041;
55+
border-color: #a80041;
56+
}
57+
58+
.projects {
59+
margin: 1rem;
60+
border: 1px solid #ff0062;
61+
}
62+
63+
.projects header {
64+
background: #ff0062;
65+
height: 3.5rem;
66+
display: flex;
67+
justify-content: center;
68+
align-items: center;
69+
}
70+
71+
#finished-projects {
72+
border-color: #0044ff;
73+
}
74+
75+
#finished-projects header {
76+
background: #0044ff;
77+
}
78+
79+
.projects h2 {
80+
margin: 0;
81+
color: white;
82+
}
83+
84+
.projects ul {
85+
list-style: none;
86+
margin: 0;
87+
padding: 1rem;
88+
}
89+
90+
.projects li {
91+
box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.26);
92+
padding: 1rem;
93+
margin: 1rem;
94+
background: white;
95+
}
96+
97+
.projects li h2 {
98+
color: #ff0062;
99+
margin: 0.5rem 0;
100+
}
101+
102+
#finished-projects li h2 {
103+
color: #0044ff;
104+
}
105+
106+
.projects li h3 {
107+
color: #575757;
108+
font-size: 1rem;
109+
}
110+
111+
.project li p {
112+
margin: 0;
113+
}
114+
115+
.droppable {
116+
background: #ffe3ee;
117+
}
118+
119+
#finished-projects .droppable {
120+
background: #d6e1ff;
121+
}
122+
123+
#user-input {
124+
margin: 1rem;
125+
padding: 1rem;
126+
border: 1px solid #ff0062;
127+
background: #f7f7f7;
128+
}

0 commit comments

Comments
 (0)