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
TypeScript 速成课(A crash course in TypeScript) #34
TypeScript 速成课(A crash course in TypeScript) #34
Conversation
@lihroff @jingruzhang 领取校对 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lihroff @jingruzhang 原文很长,一些术语和专业知识翻译的很准确,调整了一些语序
|
||
# TypeScript 速成课 | ||
|
||
Typescript 是 javascript 的类型超集,旨在简化大型 JavaScript 应用程序的开发。Typescript 加入了常见的概率例如 类(classes),范型(generics),接口(interfaces)和静态类型(static types)并允许开发人员使用静态检查和代码重构等工具。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typescript 加入了常见的概率例如
Typescript 加入了常见的概念例如
|
||
## 为什么在意 Typescript: | ||
|
||
现在问题仍然是为什么你应该 优选使用 Typescript。这有一些关于为什么 javascript 开发者应该考虑学习 Typescript 的原因。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在问题仍然是为什么你应该 � 优选使用
现在问题仍然是为什么你应该优选使用
|
||
### 静态类型: | ||
|
||
Javascript 是动态类型的,这意味着它不知道变量的类型,直到它在运行时实例化它,这可能导致项目中的问题和错误。Typescript 加入了对 Javascript 静态类型支持如果你正确的使用它处理 由变量类型的错误设定 引起的错误。您仍然可以完全控制输入代码的严格程度,或者甚至根本不使用类型。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typescript 加入了对 Javascript 静态类型支持如果你正确的使用它处理 � 由变量类型的错误设定 � 引起的错误。
Typescript 加入了对 Javascript 静态类型支持,如果你正确的使用它可以避免由变量类型推断引起的错误。
|
||
### 更好的 IDE 支持: | ||
|
||
Typescript 相比 Javascript 一个更大的优势是更好的 IED 支持包括了来自 Typescript 编译器 智能,实时的提示,调试以及更多功能。这里还有一大堆扩展进一步 提升你的 Typescript 开发体验。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typescript 相比 �Javascript 一个更大的优势是更好的 IED 支持包括了来自 �Typescript� 编译器 � 智能,实时的提示,调试以及更多功能。这里还有一大堆扩展进一步 � 提升你的 Typescript 开发体验。
Typescript 相比 Javascript 一个更大的优势是更好的 IED 支持,包括来自 Typescript 编译器的智能、实时提示,更更方便的调试等功能。还有海量扩展提升 Typescript 的开发体验。
|
||
## 什么时候你该使用它: | ||
|
||
到目前为止,我们应该知道为什么 Typescript 是有用的以及如何改善我们的开发经验。但它并不是解决所有问题的方法,当然也不能阻止你自己编写可怕的代码。那么让我们来看看你应该在哪里使用 Typescript。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typescript 是有用的以及如何改善我们的开发经验。
Typescript 是有用的以及如何改善我们的开发体验。
} | ||
``` | ||
|
||
然而 any 是范型,某种程度它 能接受所有类型参数但有一个很大的区别。我们丢失了我们传入的参数是什么类型以及返回值是什么类型。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
然而 any 是范型,某种程度它 � 能接受所有类型参数但有一个很大的区别。
然而 any 是能接受所有类型参数的特殊泛型,但有一个很大的区别。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
然而 any 是通用的,某种程度它能接受所有类型参数但有一个很大的区别。
这里的generic应该不代表术语范型而是通用的,之前留过注释。
import { Person, Animal, Human } from 'index'; | ||
``` | ||
|
||
## 范型(Generics): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## 范型(Generics):
## 泛型(Generics):
下同
|
||
这里我们使用泛型参数 T,因此我们可以捕获变量类型并在以后使用它。我们还使用它作为返回参数类型,它允许我们在检查代码时看到相应的类型。 | ||
|
||
更多详细接受你可以查看[Charly Poly]()关于[Generics and overloads](https://medium.com/@wittydeveloper/typescript-generics-and-overloads-999679d121cf)的文章 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
更多详细接受你可以查看
更多详细介绍你可以查看
|
||
### 受保护的: | ||
|
||
保护成员只能在其定义的类和每一个定义的 超/子类中能访问。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
保护成员只能在其定义的类和每一个定义的 � 超/子类中能访问。
保护成员只能在其定义的类及其子类中访问。
我们可以通过将它们放在 rules 对象中来添加其他规则。 | ||
|
||
```json | ||
"rules": { "no-unnecessary-type-assertion": true, "array-type": [true, "array"], "no-double-space": true, "no-var-keyword": true, "semicolon": [true, "always", "ignore-bound-class-methods"]}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"rules": { "no-unnecessary-type-assertion": true, "array-type": [true, "array"], "no-double-space": true, "no-var-keyword": true, "semicolon": [true, "always", "ignore-bound-class-methods"]},
"rules": {
"no-unnecessary-type-assertion": true,
"array-type": [true, "array"],
"no-double-space": true,
"no-var-keyword": true,
"semicolon": [true, "always", "ignore-bound-class-methods"]
},
谢谢 @ZhichengChen 校对,请 @lihroff 确认校对建议,我也会协助看看,然后 @lihroff 修改终稿之后再 commit 一次,我来 merge。 |
done |
@miyaliu666 reviewed |
Translate into Chinese.