Skip to content

Commit edf7376

Browse files
committed
complete ts chapter 2
1 parent 6a83ea2 commit edf7376

File tree

9 files changed

+151
-4
lines changed

9 files changed

+151
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

chapters/1/codes/1.3/app.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ class myContainer {
99
};
1010

1111
let createObj = new myContainer("Hi Morol!");
12-
console.log(createObj);
1312
console.log(createObj.getData());

chapters/2/codes/2.1/app.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
3+
If you find the arguments for type systems persuasive in general, then you'll be happy with TypeScript.
4+
It brings many of the advantages of type system (safety, readability, improved tooling) to the
5+
JavaScript ecosystem. It also suffers from some of the drawbacks of type systems (added complexity
6+
and incompleteness).
7+
8+
*/
9+
10+
function double(num: number): number {
11+
return num * 5;
12+
}
13+
14+
/*
15+
console.log(double('6'));
16+
17+
myTs.ts:5:20 - error TS2345: Argument of type '"6"' is not assignable
18+
to parameter of type 'number'.
19+
*/
20+
21+
console.log(double(6)); // 30

chapters/2/codes/2.2/app.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// TypeScript enables editors to provide contextual documentation:
2+
3+
'morol'.slice();
4+
5+
/*
6+
7+
slice(start?: number, end?: number): string
8+
The index to the beginning of the specified portion of stringObj.
9+
Returns a section of a string.
10+
11+
*/
12+
13+
// You'll never forget whether String.prototype.slice takes (start, stop) or (start, length) again!

chapters/2/codes/2.3/app.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
3+
TypeScript allows editors to perform automated refactors which are aware of the rules
4+
of the languages.
5+
6+
*/
7+
8+
let ans = 'morol';
9+
{
10+
let ans = (num: number) => {
11+
return 5 * num;
12+
}
13+
14+
//console.log(ans); // [Function: ans_1]
15+
console.log(ans(10)) // 50
16+
}
17+
18+
console.log(ans); // morol
19+
20+
/*
21+
Here, for instance, Visual Studio Code is able to rename references to the inner ans without
22+
altering the outer ans. This would be difficult to do with a simple find/replace.
23+
*/

chapters/2/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
| **Topic** | **Code** |
44
|:---------:|:--------:|
5-
| Section 2.1: Safety | [code-here](/chapters/2/codes/2.0/app.md) |
6-
| Section 2.2: Readability | [code-here](/chapters/2/codes/2.1/app.md) |
7-
| Section 2.3: Tooling | [code-here](/chapters/2/codes/2.2/app.md) |
5+
| Section 2.1: Safety | [code-here](/chapters/2/codes/2.1/app.ts) |
6+
| Section 2.2: Readability | [code-here](/chapters/2/codes/2.2/app.ts) |
7+
| Section 2.3: Tooling | [code-here](/chapters/2/codes/2.3/app.ts) |

myTs.ts

Whitespace-only changes.

package-lock.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "type-script",
3+
"version": "1.0.0",
4+
"description": "| Chapter | Details | |:-------:|:-------:| | 1: Getting started with TypeScript | [Readme](/chapters/1/readme.md) | | 2: Why and when to use TypeScript | [Readme](/chapters/2/readme.md) | | 3: TypeScript Core Types | [Readme]() | | 4: Arrays | [Readme]() | | 5: Enums | [Readme]() | | 6: Functions | [Readme]() | | 7: Classes | [Readme]() | | 8: Class Decorator | [Readme]() | | 9: Interfaces | [Readme]() | | 10: Generics | [Readme]() | | 11: Strict null checks | [Readme]() | | 12: User-defined Type Guards | [Readme]() | | 13: TypeScript basic examples | [Readme]() | | 14: Importing external libraries | [Readme]() | | 15: Modules - exporting and importing | [Readme]() | | 16: Publish TypeScript definition files | [Readme]() | | 17: Using TypeScript with webpack | [Readme]() | | 18: Mixins | [Readme]() | | 19: How to use a JavaScript library without a type definition file | [Readme]() | | 20: TypeScript installing typescript and running the typescript compiler tsc | [Readme]() | | 21: Configure typescript project to compile all files in typescript. | [Readme]() | | 22: Integrating with Build Tools | [Readme]() | | 23: Using TypeScript with RequireJS | [Readme]() | | 24: TypeScript with AngularJS | [Readme]() | | 25: TypeScript with SystemJS | [Readme]() | | 26: Using TypeScript with React (JS & native) | [Readme]() | | 27: TSLint - assuring code quality and consistency | [Readme]() | | 28: tsconfig.json | [Readme]() | | 29: Debugging | [Readme]() | | 30: Unit Testing | [Readme]() |",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "nodemon myTs.ts"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/pro-js/typeScript-Professionals.git"
12+
},
13+
"author": "Morol",
14+
"license": "ISC",
15+
"bugs": {
16+
"url": "https://github.com/pro-js/typeScript-Professionals/issues"
17+
},
18+
"homepage": "https://github.com/pro-js/typeScript-Professionals#readme",
19+
"devDependencies": {
20+
"typescript": "^3.9.5"
21+
},
22+
"dependencies": {
23+
"ts-node": "^8.10.2"
24+
}
25+
}

0 commit comments

Comments
 (0)