Skip to content

Minor changes #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ Simone Poggiali 是一位经验丰富的高级前端开发人员,自 90 年代

TypeScript 是一种基于 JavaScript 构建的强类型编程语言。它最初由 Anders Hejlsberg 于 2012 年设计,目前由 Microsoft 作为开源项目开发和维护。

TypeScript 编译为 JavaScript,并且可以在任何 JavaScript 引擎(例如浏览器或服务器 Node.js)中执行。
TypeScript 编译为 JavaScript,并且可以在任何 JavaScript 运行时(例如浏览器或服务器 Node.js)中执行。

TypeScript 支持多种编程范式,例如函数式、泛型、命令式和面向对象。TypeScript 既不是解释型语言,也不是编译型语言。

Expand Down Expand Up @@ -288,7 +288,7 @@ TypeScript是用`.ts`或`.tsx`文件编写的, 而JavaScript是用`.js`或`.jsx`
const sum = (a, b) => a + b;
```

该函数可以通过将文件扩展名更改为 .TypeScript 来转换和使用.ts。但是,如果同一个函数使用 TypeScript 类型进行注释,则未经编译就无法在任何 JavaScript 引擎中执行。如果未编译以下 TypeScript 代码,将会产生语法错误
该函数可以通过将文件扩展名更改为 .TypeScript 来转换和使用.ts。但是,如果同一个函数使用 TypeScript 类型进行注释,则未经编译就无法在任何 JavaScript 运行时中执行。如果未编译以下 TypeScript 代码,将会产生语法错误

<!-- skip -->
```typescript
Expand Down Expand Up @@ -332,7 +332,7 @@ const result = 1 + true; // 在JavaScript中, 结果等于2

### TypeScript 代码生成

TypeScript 编译器有两个主要职责:检查类型错误和编译为 JavaScript。这两个过程是相互独立的。类型不会影响 JavaScript 引擎中代码的执行,因为它们在编译过程中会被完全擦除。即使存在类型错误,TypeScript 仍然可以输出 JavaScript。以下是存在类型错误的 TypeScript 代码示例:
TypeScript 编译器有两个主要职责:检查类型错误和编译为 JavaScript。这两个过程是相互独立的。类型不会影响 JavaScript 运行时中代码的执行,因为它们在编译过程中会被完全擦除。即使存在类型错误,TypeScript 仍然可以输出 JavaScript。以下是存在类型错误的 TypeScript 代码示例:

<!-- skip -->
```typescript
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ You can reach Simone Poggiali on the following platforms:

TypeScript is a strongly typed programming language that builds on JavaScript. It was originally designed by Anders Hejlsberg in 2012 and is currently developed and maintained by Microsoft as an open source project.

TypeScript compiles to JavaScript and can be executed in any JavaScript engine (e.g., a browser or server Node.js).
TypeScript compiles to JavaScript and can be executed in any JavaScript runtime (e.g., a browser or server Node.js).

TypeScript supports multiple programming paradigms such as functional, generic, imperative, and object-oriented. TypeScript is neither an interpreted nor a compiled language.

Expand Down Expand Up @@ -292,7 +292,7 @@ For instance, consider a function in a JavaScript file with the `.js` extension,
const sum = (a, b) => a + b;
```

The function can be converted and used in TypeScript by changing the file extension to `.ts`. However, if the same function is annotated with TypeScript types, it cannot be executed in any JavaScript engine without compilation. The following TypeScript code will produce a syntax error if it is not compiled:
The function can be converted and used in TypeScript by changing the file extension to `.ts`. However, if the same function is annotated with TypeScript types, it cannot be executed in any JavaScript runtime without compilation. The following TypeScript code will produce a syntax error if it is not compiled:

<!-- skip -->
```typescript
Expand Down Expand Up @@ -336,7 +336,7 @@ This error occurs because TypeScript strictly enforces type compatibility, and i

### TypeScript Code Generation

The TypeScript compiler has two main responsibilities: checking for type errors and compiling to JavaScript. These two processes are independent of each other. Types do not affect the execution of the code in a JavaScript engine, as they are completely erased during compilation. TypeScript can still output JavaScript even in the presence of type errors.
The TypeScript compiler has two main responsibilities: checking for type errors and compiling to JavaScript. These two processes are independent of each other. Types do not affect the execution of the code in a JavaScript runtime, as they are completely erased during compilation. TypeScript can still output JavaScript even in the presence of type errors.
Here is an example of TypeScript code with a type error:

<!-- skip -->
Expand Down
Binary file modified downloads/typescript-book-zh_CN.epub
Binary file not shown.
Binary file modified downloads/typescript-book.epub
Binary file not shown.
3 changes: 3 additions & 0 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ website:
website-deploy:
cd ../website && npm run deploy

website-preview:
cd ../website && npm run build && npm run preview

books:
./make-books.sh
3 changes: 3 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ If you're working with Markdown books, here are some essential tools and command

Before you begin, ensure you have Node.js installed. To set up the required dependencies, use the following commands:

In folder `tools` and `website`:

```shell
nvm use
npm install
Expand All @@ -18,6 +20,7 @@ Use `make` to run the main commands:
* `make format`: Format Markdown files for books.
* `make check`: Run several checks to ensure the Markdown files are valid.
* `make website`: Create different Markdown pages for the website.
* `make website-preview`: Build and preview website.
* `make website-deploy`: Build and deploy website to GitHub Pages.
* `make books`: Create .epub books.

Expand Down
6 changes: 3 additions & 3 deletions website/src/content/docs/book/about-the-author.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Simone Poggiali is an experienced Senior Front-end Developer with a passion for

You can reach Simone Poggiali on the following platforms:

* LinkedIn: <https://www.linkedin.com/in/simone-poggiali>
* GitHub: <https://github.com/gibbok>
* Twitter: <https://twitter.com/gibbok_coding>
* LinkedIn: [https://www.linkedin.com/in/simone-poggiali](https://www.linkedin.com/in/simone-poggiali)
* GitHub: [https://github.com/gibbok](https://github.com/gibbok)
* Twitter: [https://twitter.com/gibbok_coding](https://twitter.com/gibbok_coding)
* Email: gibbok.coding📧gmail.com

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar:


TypeScript is a superset of JavaScript, it includes all the commonly used built-in JavaScript objects. You can find an extensive list of these objects on the Mozilla Developer Network (MDN) documentation website:
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects>
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects)

Here is a list of some commonly used built-in JavaScript objects:

Expand Down
16 changes: 16 additions & 0 deletions website/src/content/docs/book/downloads-and-website.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Downloads and website
sidebar:
order: 3
label: 3. Downloads and website
---


You can also download the Epub version:

[https://github.com/gibbok/typescript-book/tree/main/downloads](https://github.com/gibbok/typescript-book/tree/main/downloads)

An online version is available at:

[https://gibbok.github.io/typescript-book](https://gibbok.github.io/typescript-book)

12 changes: 0 additions & 12 deletions website/src/content/docs/book/downloads.md

This file was deleted.

10 changes: 5 additions & 5 deletions website/src/content/docs/book/exploring-the-type-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Developers can leverage a dedicated API and create their own custom language ser
An example of a real-world custom plugin is "typescript-styled-plugin", which provides syntax error reporting and IntelliSense support for CSS properties in styled components.
<!-- markdownlint-enable MD044 -->

For more information and quick start guides, you can refer to the official TypeScript Wiki on GitHub: <https://github.com/microsoft/TypeScript/wiki/>
For more information and quick start guides, you can refer to the official TypeScript Wiki on GitHub: [https://github.com/microsoft/TypeScript/wiki/](https://github.com/microsoft/TypeScript/wiki/)

### Structural Typing

Expand Down Expand Up @@ -337,10 +337,10 @@ Here few examples:
| T1 \| T2 | T1 ∪ T2 (union) | type XY = 'X' \| 'Y'; |
| | | type JK = 1 \| 2; |
| | |
| T1 & T2 | T1 ∩ T2 (intersection) | type X = { a: string } |
| | | type Y = { b: string } |
| T1 & T2 | T1 ∩ T2 (intersection) | type X = \{ a: string \} |
| | | type Y = \{ b: string \} |
| | | type XY = X & Y |
| | | const x: XY = { a: 'a', b: 'b' } |
| | | const x: XY = \{ a: 'a', b: 'b' \} |
| | |
| unknown | Universal set | const x: unknown = 1 |

Expand Down Expand Up @@ -486,7 +486,7 @@ It is worth noting that when using a type assertion, TypeScript will not execute
Ambient declarations are files that describe types for JavaScript code, they have a file name format as `.d.ts.`. They are usually imported and used to annotate existing JavaScript libraries or to add types to existing JS files in your project.

Many common libraries types can be found at:
<https://github.com/DefinitelyTyped/DefinitelyTyped/>
[https://github.com/DefinitelyTyped/DefinitelyTyped/](https://github.com/DefinitelyTyped/DefinitelyTyped/)

and can be installed using:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ Notes:

At the following link you can find the complete documentation and its schema:

<https://www.typescriptlang.org/tsconfig>
[https://www.typescriptlang.org/tsconfig](https://www.typescriptlang.org/tsconfig)

<http://json.schemastore.org/tsconfig>
[http://json.schemastore.org/tsconfig](http://json.schemastore.org/tsconfig)

The following represents a list of the common and useful configurations:

Expand Down Expand Up @@ -161,7 +161,7 @@ The first step of this transition is to introduce TypeScript into the build chai

The second step is to ensure that your JavaScript tests work alongside TypeScript files so that you can run tests as you convert each module. If you are using Jest, consider using `ts-jest`, which allows you to test TypeScript projects with Jest.

The third step is to include type declarations for third-party libraries in your project. These declarations can be found either bundled or on DefinitelyTyped. You can search for them using <https://www.typescriptlang.org/dt/search> and install them using:
The third step is to include type declarations for third-party libraries in your project. These declarations can be found either bundled or on DefinitelyTyped. You can search for them using [https://www.typescriptlang.org/dt/search](https://www.typescriptlang.org/dt/search) and install them using:

```shell
npm install --save-dev @types/package-name or yarn add --dev @types/package-name.
Expand Down
27 changes: 15 additions & 12 deletions website/src/content/docs/book/others.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,29 @@ Promises:

Promises are a way to handle asynchronous operations and their results using methods like `.then()` and `.catch()` to handle success and error conditions.

To learn more: <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise>
To learn more: [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)

Async/await:

Async/await keywords are a way to provide a more synchronous-looking syntax for working with Promises. The `async` keyword is used to define an asynchronous function, and the `await` keyword is used within an async function to pause execution until a Promise is resolved or rejected.

To learn more:
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function>
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await>
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)

The following API are well supported in TypeScript:

Fetch API:
<https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API>
[https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)

Web Workers:
<https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API>
[https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)

Shared Workers:
<https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker>
[https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker)

WebSocket:
<https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API>
[https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)

### Iterators and Generators

Expand Down Expand Up @@ -199,7 +199,10 @@ for (const num of generator) {
TypeScript also supports async iterators and async Generators.

To learn more:
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator>

[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator)

[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator)

### TsDocs JSDoc Reference

Expand All @@ -221,11 +224,11 @@ power(10, 2); // function power(base: number, exponent: number): number
```

Full documentation is provided to this link:
<https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html>
[https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html)

From version 3.7 it is possible to generate .d.ts type definitions from JavaScript JSDoc syntax.
More information can be found here:
<https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html>
[https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html](https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html)

### @types

Expand All @@ -237,7 +240,7 @@ npm install --save-dev @types/lodash

Will install the type definitions of `lodash` in your current project.

To contribute to the type definitions of @types package, please submit a pull request to <https://github.com/DefinitelyTyped/DefinitelyTyped>.
To contribute to the type definitions of @types package, please submit a pull request to [https://github.com/DefinitelyTyped/DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped).

### JSX

Expand All @@ -251,7 +254,7 @@ To use JSX you need to set the `jsx` compiler option in your `tsconfig.json` fil
* "react": enables TypeScript's built-in JSX transformation. React.createElement will be used.

All options are available here:
<https://www.typescriptlang.org/tsconfig#jsx>
[https://www.typescriptlang.org/tsconfig#jsx](https://www.typescriptlang.org/tsconfig#jsx)

### ES6 Modules

Expand Down
2 changes: 1 addition & 1 deletion website/src/content/docs/book/table-of-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sidebar:
<!-- markdownlint-disable MD004 -->
- The Concise TypeScript Book
- Translations
- Downloads
- Downloads and website
- Table of Contents
- Introduction
- About the Author
Expand Down
2 changes: 1 addition & 1 deletion website/src/content/docs/book/translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ sidebar:

This book has been translated into several language versions, including:

* [Chinese](./README-zh_CN.md)
[Chinese](https://github.com/gibbok/typescript-book/blob/main/README-zh_CN.md)

6 changes: 3 additions & 3 deletions website/src/content/docs/book/typescript-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sidebar:

TypeScript is a strongly typed programming language that builds on JavaScript. It was originally designed by Anders Hejlsberg in 2012 and is currently developed and maintained by Microsoft as an open source project.

TypeScript compiles to JavaScript and can be executed in any JavaScript engine (e.g., a browser or server Node.js).
TypeScript compiles to JavaScript and can be executed in any JavaScript runtime (e.g., a browser or server Node.js).

TypeScript supports multiple programming paradigms such as functional, generic, imperative, and object-oriented. TypeScript is neither an interpreted nor a compiled language.

Expand Down Expand Up @@ -43,7 +43,7 @@ For instance, consider a function in a JavaScript file with the `.js` extension,
const sum = (a, b) => a + b;
```

The function can be converted and used in TypeScript by changing the file extension to `.ts`. However, if the same function is annotated with TypeScript types, it cannot be executed in any JavaScript engine without compilation. The following TypeScript code will produce a syntax error if it is not compiled:
The function can be converted and used in TypeScript by changing the file extension to `.ts`. However, if the same function is annotated with TypeScript types, it cannot be executed in any JavaScript runtime without compilation. The following TypeScript code will produce a syntax error if it is not compiled:

<!-- skip -->
```typescript
Expand Down Expand Up @@ -87,7 +87,7 @@ This error occurs because TypeScript strictly enforces type compatibility, and i

### TypeScript Code Generation

The TypeScript compiler has two main responsibilities: checking for type errors and compiling to JavaScript. These two processes are independent of each other. Types do not affect the execution of the code in a JavaScript engine, as they are completely erased during compilation. TypeScript can still output JavaScript even in the presence of type errors.
The TypeScript compiler has two main responsibilities: checking for type errors and compiling to JavaScript. These two processes are independent of each other. Types do not affect the execution of the code in a JavaScript runtime, as they are completely erased during compilation. TypeScript can still output JavaScript even in the presence of type errors.
Here is an example of TypeScript code with a type error:

<!-- skip -->
Expand Down
6 changes: 3 additions & 3 deletions website/src/content/docs/zh-cn/book/about-the-author.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Simone Poggiali 是一位经验丰富的高级前端开发人员,自 90 年代

您可以通过以下平台联系 Simone Poggiali:

* 领英: <https://www.linkedin.com/in/simone-poggiali>
* GitHub: <https://github.com/gibbok>
* 推特: <https://twitter.com/gibbok_coding>
* 领英: [https://www.linkedin.com/in/simone-poggiali](https://www.linkedin.com/in/simone-poggiali)
* GitHub: [https://github.com/gibbok](https://github.com/gibbok)
* 推特: [https://twitter.com/gibbok_coding](https://twitter.com/gibbok_coding)
* 电子邮箱: gibbok.coding📧gmail.com

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar:


TypeScript 是 JavaScript 的超集,它包含所有常用的内置 JavaScript 对象。您可以在 Mozilla 开发者网络 (MDN) 文档网站上找到这些对象的详细列表:
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects>
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects)

以下是一些常用的内置 JavaScript 对象的列表:

Expand Down
Loading
Loading