Skip to content

Commit 62c83c0

Browse files
basaratyottahmd
authored andcommitted
Squashed commits
1 parent 66ec7e3 commit 62c83c0

File tree

318 files changed

+317791
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

318 files changed

+317791
-3
lines changed

.gitattributes

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# core.autocrlf
2+
* text=auto
3+
4+
*.js linguist-language=TypeScript

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Mac
2+
*.DS_Store
3+
4+
# IDEs
5+
.alm
6+
.vscode
7+
8+
9+
# Node rules:
10+
## Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
11+
.grunt
12+
13+
## Dependency directory
14+
## Commenting this out is preferred by some people, see
15+
## https://docs.npmjs.com/misc/faq#should-i-check-my-node_modules-folder-into-git
16+
node_modules
17+
18+
# Book build output
19+
_book
20+
21+
# eBook build output
22+
*.epub
23+
*.mobi
24+
*.pdf

CONTRIBUTING.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Contributing
2+
3+
This book is developed using [GitBook](https://github.com/GitbookIO/gitbook). Authored in Markdown files (I use [atom](http://atom.io)).
4+
5+
Here's how to setup a Dev Environment:
6+
7+
```
8+
npm install gitbook-cli -g
9+
gitbook serve .
10+
```
11+
> Note: serve needs port `35729` (for live reload) and `4000` for serving http://localhost:4000.
12+
13+
Also you can mostly just edit the `.md` files in [`/docs`](https://github.com/basarat/typescript-book/docs) using github and create a Pull Request (PR).
14+
15+
# Code
16+
All the code for the book is in the `/code` folder. Tested with `atom-typescript`.
17+
18+
### More Gitbook Tips
19+
* Links best work if they are relative (e.g. `./foo.md`) to the *current* file.
20+
* For links in the same file (`#foo-bar` style links) best to click the heading on github to get what gitbook expects.
21+
22+
### TypeScript Compiler Docs
23+
Thanks to the TypeScript team for providing much of the docs: https://github.com/Microsoft/TypeScript/wiki/Architectural-Overview that are used to write the compiler story.

GLOSSARY.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Duck Typing
2+
If it walks like a duck and quacks like a duck, it is a duck. For TypeScript if it has all the members structurally then it is okay for other things (irrespecitive of name) that accept that structure.
3+
4+
# OE
5+
Operating Environment. I'd like to use the term Operating System, but that is not necessarily what I mean here. Think Browser,Node.js,WScriptHost etc.
6+
7+
# Incremental Parsing
8+
Re-Parsing as the user edits the code.

LICENSE.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Creative Commons
2+
3+
https://creativecommons.org/licenses/by/4.0/

README.md

+53-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,56 @@
1-
The Ultimate Guide to TypeScript
1+
TypeScript Deep Dive
22
=======
33

4-
I've been looking at the issues that turn up commonly when people start using TypeScript. This is based on the lessons from [StackOverflow](http://stackoverflow.com/tags/typescript/topusers) / [DefinitelyTyped](https://github.com/DefinitelyTyped/) and general engagement with the [TypeScript community](https://github.com/TypeStrong/).
4+
I've been looking at the issues that turn up commonly when people start using TypeScript. This is based on the lessons from [Stack Overflow](http://stackoverflow.com/tags/typescript/topusers) / [DefinitelyTyped](https://github.com/DefinitelyTyped/) and general engagement with the [TypeScript community](https://github.com/TypeStrong/). You can [follow for updates](https://twitter.com/basarat) and [don't forget to ★ on GitHub](https://github.com/basarat/typescript-book) 🌹
55

6-
Your feedback on this [work is highly appreciated](https://twitter.com/basarat).
6+
## Reviews
7+
8+
* Thanks for the wonderful book. Learned a lot from it. ([link](https://www.gitbook.com/book/basarat/typescript/discussions/21#comment-1468279131934))
9+
* Its probably the Best TypeScript book out there. Good Job ([link](https://twitter.com/thelondonjs/status/756419561570852864))
10+
* Love how precise and clear the examples and explanations are! ([link](https://twitter.com/joe_mighty/status/758290957280346112))
11+
* For the low, low price of free, you get pages of pure awesomeness. Chock full of source code examples and clear, concise explanations, TypeScript Deep Dive will help you learn TypeScript development. ([link](https://www.nativescript.org/blog/details/free-book-typescript-deep-dive))
12+
* Just a big thank you! **Best TypeScript 2 detailed explanation!** ([link](https://www.gitbook.com/book/basarat/typescript/discussions/38))
13+
* This gitbook got my project going pronto. Fluent easy read 5 stars. ([link](https://twitter.com/thebabellion/status/779888195559235584))
14+
* I recommend the online #typescript book by @basarat you'll love it.([link](https://twitter.com/markpieszak/status/788099306590969860))
15+
* I've always found this by @basarat really helpful. ([link](https://twitter.com/Brocco/status/789887640656945152))
16+
* We must highlight TypeScript Deep Dive, an open source book.([link](https://www.siliconrepublic.com/enterprise/typescript-programming-javascript))
17+
* Great online resource for learning. ([link](https://twitter.com/rdfuhr/status/790193307708076035))
18+
* Thank you for putting this book together, and for all your hard work within the TypeScript community. ([link](https://github.com/basarat/typescript-book/pull/183#issuecomment-257799713))
19+
* TypeScript Deep Dive is one of the best technical texts I've read in a while. ([link](https://twitter.com/borekb/status/794287092272599040))
20+
* Thanks @basarat for the TypeScript Deep Dive Book. Help me a lot with my first TypeScript project. ([link](https://twitter.com/betolinck/status/797901548562960384))
21+
* Thanks to @basarat for this great #typescript learning resource. ([link](https://twitter.com/markuse1501/status/799116176815230976))
22+
* Guyz excellent book on Typescript(@typescriptlang) by @basarat ([link](https://twitter.com/deeinlove/status/813245965507260417))
23+
* Leaning on the legendary @basarat's "TypeScript Deep Dive" book heavily at the moment ([link](https://twitter.com/sitapati/status/814379404956532737))
24+
* numTimesPointedPeopleToBasaratsTypeScriptBook++; ([link](https://twitter.com/brocco/status/814227741696462848))
25+
* A book not only for typescript, a good one for deeper JavaScript knowledge as well. [link](https://www.gitbook.com/book/basarat/typescript/discussions/59)
26+
* In my new job, we're using @typescriptlang, which I am new to. This is insanely helpful huge thanks, @basarat! [link](https://twitter.com/netchkin/status/855339390566096896)
27+
* Thank you for writing TypeScript Deep Dive. I have learned so much. [link](https://twitter.com/buctwbzs/status/857198618704355328?refsrc=email&s=11)
28+
* Loving @basarat's @typescriptlang online book basarat.gitbooks.io/typescript/# loaded with great recipes! [link](https://twitter.com/ericliprandi/status/857608837309677568)
29+
* Microsoft doc is great already, but if want to "dig deeper" into TypeScript I find this book of great value [link](https://twitter.com/caludio/status/876729910550831104)
30+
* Thanks, this is a great book 🤓🤓 [link](https://twitter.com/jjwonmin/status/885666375548547073)
31+
* Deep dive to typescript is awesome in so many levels. i find it very insightful. Thanks [link](https://twitter.com/orenmizr/status/891083492787970053)
32+
* @basarat's intro to @typescriptlang is still one of the best going (if not THE best) [link](https://twitter.com/stevealee/status/953953255968698368)
33+
* This is sweet! So many #typescript goodies! [link](https://twitter.com/pauliescanlon/status/989898852474998784)
34+
35+
## Get Started
36+
If you are here to read the book online [get started](http://basarat.gitbooks.io/typescript/content/docs/getting-started.html).
37+
38+
## Translations
39+
Book is completely free so you can copy paste whatever you want without requiring permission. If you have a translation you want me to link here. [Send a PR](https://github.com/basarat/typescript-book/edit/master/README.md).
40+
* [Filipino](https://github.com/themarshann/typescript-book-fil)
41+
* [Italian](https://github.com/TizioFittizio/typescript-book)
42+
* [Chinese](https://github.com/jkchao/typescript-book-chinese)
43+
* [Russian](https://github.com/etroynov/typescript-book)
44+
* [Portuguese](https://github.com/overlineink/typescript-book)
45+
46+
## Other Options
47+
You can also download one of the following:
48+
* [EPUB for iPad, iPhone, Mac](https://www.gitbook.com/download/epub/book/basarat/typescript)
49+
* [PDF for Windows and others](https://www.gitbook.com/download/pdf/book/basarat/typescript)
50+
* [MOBI for Kindle](https://www.gitbook.com/download/mobi/book/basarat/typescript)
51+
52+
## Special Thanks
53+
All the amazing [contributors](https://github.com/basarat/typescript-book/graphs/contributors) 🌹
54+
55+
## Share
56+
Share URL: http://basarat.gitbooks.io/typescript/

SUMMARY.md

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Summary
2+
3+
* [Getting Started](docs/getting-started.md)
4+
* [Why TypeScript](docs/why-typescript.md)
5+
* [JavaScript](docs/javascript/recap.md)
6+
* [Equality](docs/javascript/equality.md)
7+
* [References](docs/javascript/references.md)
8+
* [Null vs. Undefined](docs/javascript/null-undefined.md)
9+
* [this](docs/javascript/this.md)
10+
* [Closure](docs/javascript/closure.md)
11+
* [Number](docs/javascript/number.md)
12+
* [Truthy](docs/javascript/truthy.md)
13+
* [Future JavaScript Now](docs/future-javascript.md)
14+
* [Classes](docs/classes.md)
15+
* [Classes Emit](docs/classes-emit.md)
16+
* [Arrow Functions](docs/arrow-functions.md)
17+
* [Rest Parameters](docs/rest-parameters.md)
18+
* [let](docs/let.md)
19+
* [const](docs/const.md)
20+
* [Destructuring](docs/destructuring.md)
21+
* [Spread Operator](docs/spread-operator.md)
22+
* [for...of](docs/for...of.md)
23+
* [Iterators](docs/iterators.md)
24+
* [Template Strings](docs/template-strings.md)
25+
* [Promise](docs/promise.md)
26+
* [Generators](docs/generators.md)
27+
* [Async Await](docs/async-await.md)
28+
* [Project](docs/project/project.md)
29+
* [Compilation Context](docs/project/compilation-context.md)
30+
* [tsconfig.json](docs/project/tsconfig.md)
31+
* [Which Files?](docs/project/files.md)
32+
* [Declaration Spaces](docs/project/declarationspaces.md)
33+
* [Modules](docs/project/modules.md)
34+
* [File Module Details](docs/project/external-modules.md)
35+
* [globals.d.ts](docs/project/globals.md)
36+
* [Namespaces](docs/project/namespaces.md)
37+
* [Dynamic Import Expressions](docs/project/dynamic-import-expressions.md)
38+
* [Node.js QuickStart](docs/quick/nodejs.md)
39+
* [Browser QuickStart](docs/quick/browser.md)
40+
* [TypeScript's Type System](docs/types/type-system.md)
41+
* [JS Migration Guide](docs/types/migrating.md)
42+
* [@types](docs/types/@types.md)
43+
* [Ambient Declarations](docs/types/ambient/intro.md)
44+
* [Declaration Files](docs/types/ambient/d.ts.md)
45+
* [Variables](docs/types/ambient/variables.md)
46+
* [Interfaces](docs/types/interfaces.md)
47+
* [Enums](docs/enums.md)
48+
* [`lib.d.ts`](docs/types/lib.d.ts.md)
49+
* [Functions](docs/types/functions.md)
50+
* [Callable](docs/types/callable.md)
51+
* [Type Assertion](docs/types/type-assertion.md)
52+
* [Freshness](docs/types/freshness.md)
53+
* [Type Guard](docs/types/typeGuard.md)
54+
* [Literal Types](docs/types/literal-types.md)
55+
* [Readonly](docs/types/readonly.md)
56+
* [Generics](docs/types/generics.md)
57+
* [Type Inference](docs/types/type-inference.md)
58+
* [Type Compatibility](docs/types/type-compatibility.md)
59+
* [Never Type](docs/types/never.md)
60+
* [Discriminated Unions](docs/types/discriminated-unions.md)
61+
* [Index Signatures](docs/types/index-signatures.md)
62+
* [Moving Types](docs/types/moving-types.md)
63+
* [Exception Handling](docs/types/exceptions.md)
64+
* [Mixins](docs/types/mixins.md)
65+
* [JSX](docs/jsx/tsx.md)
66+
* [React](docs/jsx/react.md)
67+
* [Non React JSX](docs/jsx/others.md)
68+
* [Options](docs/options/intro.md)
69+
* [noImplicitAny](docs/options/noImplicitAny.md)
70+
* [strictNullChecks](docs/options/strictNullChecks.md)
71+
* [Errors in TypeScript](docs/errors/main.md)
72+
* [Interpreting Errors](docs/errors/interpreting-errors.md)
73+
* [Common Errors](docs/errors/common-errors.md)
74+
* [NPM](docs/npm/index.md)
75+
* [Testing](docs/testing/intro.md)
76+
* [Jest](docs/testing/jest.md)
77+
* [Cypress](docs/testing/cypress.md)
78+
* [Tools](docs/tools/intro.md)
79+
* [Prettier](docs/tools/prettier.md)
80+
* [Husky](docs/tools/husky.md)
81+
* [Changelog](docs/tools/changelog.md)
82+
* [TIPs](docs/tips/main.md)
83+
* [String Based Enums](docs/tips/stringEnums.md)
84+
* [Nominal Typing](docs/tips/nominalTyping.md)
85+
* [Stateful Functions](docs/tips/statefulFunctions.md)
86+
* [Bind is Bad](docs/tips/bind.md)
87+
* [Currying](docs/tips/currying.md)
88+
* [Type Instantiation](docs/tips/typeInstantiation.md)
89+
* [Lazy Object Literal Initialization](docs/tips/lazyObjectLiteralInitialization.md)
90+
* [Classes are Useful](docs/tips/classesAreUseful.md)
91+
* [Avoid Export Default](docs/tips/defaultIsBad.md)
92+
* [Limit Property Setters](docs/tips/propertySetters.md)
93+
* [`outFile` caution](docs/tips/outFile.md)
94+
* [JQuery tips](docs/tips/jquery.md)
95+
* [static constructors](docs/tips/staticConstructor.md)
96+
* [singleton pattern](docs/tips/singleton.md)
97+
* [Function parameters](docs/tips/functionParameters.md)
98+
* [Build Toggles](docs/tips/build-toggles.md)
99+
* [Barrel](docs/tips/barrel.md)
100+
* [Create Arrays](docs/tips/create-arrays.md)
101+
* [Typesafe Event Emitter](docs/tips/typed-event.md)
102+
* [StyleGuide](docs/styleguide/styleguide.md)
103+
* [TypeScript Compiler Internals](docs/compiler/overview.md)
104+
* [Program](docs/compiler/program.md)
105+
* [AST](docs/compiler/ast.md)
106+
* [TIP: Visit Children](docs/compiler/ast-tip-children.md)
107+
* [TIP: SyntaxKind enum](docs/compiler/ast-tip-syntaxkind.md)
108+
* [Trivia](docs/compiler/ast-trivia.md)
109+
* [Scanner](docs/compiler/scanner.md)
110+
* [Parser](docs/compiler/parser.md)
111+
* [Parser Functions](docs/compiler/parser-functions.md)
112+
* [Binder](docs/compiler/binder.md)
113+
* [Binder Functions](docs/compiler/binder-functions.md)
114+
* [Binder Declarations](docs/compiler/binder-declarations.md)
115+
* [Binder Container](docs/compiler/binder-container.md)
116+
* [Binder SymbolTable](docs/compiler/binder-symboltable.md)
117+
* [Binder Error Reporting](docs/compiler/binder-diagnostics.md)
118+
* [Checker](docs/compiler/checker.md)
119+
* [Checker Diagnostics](docs/compiler/checker-global.md)
120+
* [Checker Error Reporting](docs/compiler/checker-diagnostics.md)
121+
* [Emitter](docs/compiler/emitter.md)
122+
* [Emitter Functions](docs/compiler/emitter-functions.md)
123+
* [Emitter SourceMaps](docs/compiler/emitter-sourcemaps.md)
124+
* [Contributing](docs/compiler/contributing.md)

book.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"language": "en",
3+
"author": "Basarat Ali Syed",
4+
"title": "TypeScript Deep Dive",
5+
"plugins": ["edit-link", "github", "adsense","header"],
6+
"pluginsConfig": {
7+
"layout": {
8+
"headerPath" : "header.html"
9+
},
10+
"lunr": {
11+
"ignoreSpecialCharacters": true
12+
},
13+
"edit-link": {
14+
"base": "https://github.com/basarat/typescript-book/tree/master",
15+
"label": "Edit This Page"
16+
},
17+
"github": {
18+
"url": "https://github.com/basarat/typescript-book/"
19+
},
20+
"adsense": {
21+
"client": "ca-pub-4656761253552116",
22+
"slot": "2017468453",
23+
"format": "auto",
24+
"element": ".page-inner section",
25+
"position": "bottom"
26+
}
27+
}
28+
}

code/async-await/es5/asyncAwaitES5.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2+
return new (P || (P = Promise))(function (resolve, reject) {
3+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
4+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
5+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
6+
step((generator = generator.apply(thisArg, _arguments || [])).next());
7+
});
8+
};
9+
var __generator = (this && this.__generator) || function (thisArg, body) {
10+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
11+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12+
function verb(n) { return function (v) { return step([n, v]); }; }
13+
function step(op) {
14+
if (f) throw new TypeError("Generator is already executing.");
15+
while (_) try {
16+
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
17+
if (y = 0, t) op = [0, t.value];
18+
switch (op[0]) {
19+
case 0: case 1: t = op; break;
20+
case 4: _.label++; return { value: op[1], done: false };
21+
case 5: _.label++; y = op[1]; op = [0]; continue;
22+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
23+
default:
24+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
25+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
26+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
27+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
28+
if (t[2]) _.ops.pop();
29+
_.trys.pop(); continue;
30+
}
31+
op = body.call(thisArg, _);
32+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
33+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
34+
}
35+
};
36+
function delay(milliseconds, count) {
37+
return new Promise(function (resolve) {
38+
setTimeout(function () {
39+
resolve(count);
40+
}, milliseconds);
41+
});
42+
}
43+
// async function always return a Promise
44+
function dramaticWelcome() {
45+
return __awaiter(this, void 0, void 0, function () {
46+
var i, count;
47+
return __generator(this, function (_a) {
48+
switch (_a.label) {
49+
case 0:
50+
console.log("Hello");
51+
i = 0;
52+
_a.label = 1;
53+
case 1:
54+
if (!(i < 5)) return [3 /*break*/, 4];
55+
return [4 /*yield*/, delay(500, i)];
56+
case 2:
57+
count = _a.sent();
58+
console.log(count);
59+
_a.label = 3;
60+
case 3:
61+
i++;
62+
return [3 /*break*/, 1];
63+
case 4:
64+
console.log("World!");
65+
return [2 /*return*/];
66+
}
67+
});
68+
});
69+
}
70+
dramaticWelcome();

code/async-await/es5/asyncAwaitES5.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function delay(milliseconds: number, count: number): Promise<number> {
2+
return new Promise<number>(resolve => {
3+
setTimeout(() => {
4+
resolve(count);
5+
}, milliseconds);
6+
});
7+
}
8+
9+
// async function always return a Promise
10+
async function dramaticWelcome(): Promise<void> {
11+
console.log("Hello");
12+
13+
for (let i = 0; i < 5; i++) {
14+
// await is converting Promise<number> into number
15+
const count:number = await delay(500, i);
16+
console.log(count);
17+
}
18+
19+
console.log("World!");
20+
}
21+
22+
dramaticWelcome();

code/async-await/es5/tsconfig.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */
4+
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
5+
"lib": ["dom", "es2015.promise", "es5"] /* Specify library files to be included in the compilation: */
6+
},
7+
"files": [
8+
"./asyncAwaitES5.ts"
9+
]
10+
}

0 commit comments

Comments
 (0)