-
Notifications
You must be signed in to change notification settings - Fork 130
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
translate-zh: get-started/ts for the new programmer.md #51
Conversation
Thanks for the PR! This section of the codebase is owned by @Kingwl - if they write a comment saying "LGTM" then it will be merged. |
Translation of TS for the New Programmer.mdtitle: TypeScript for beginners in programming oneline: Learn TypeScript from scratchCongratulations on choosing TypeScript as your first programming language – you've made the smart decision! You may have heard that TypeScript is a "spice" or "variant" of JavaScript. The relationship between TypeScript (TS) and JavaScript (JS) is quite unique in modern programming languages, so understanding this relationship further will help you understand how to add TypeScript to JavaScript. What is JavaScript? A brief historyJavaScript (also known as ECMAScript) was born as a simple browser scripting language. When it was invented, it was expected to be used for short code snippets embedded in web pages. These fragments usually do not exceed a few dozen lines. As a result, early Web browsers executed such code very slowly. However, over time, JS became more popular, and web developers began to use it to create interactive experiences. Web browser developers cope with the increasing use of JS by optimizing the execution engine (dynamic compilation) and extending what can be done (adding APIs), which in turn makes web developers more use of JS. On modern websites, your browser often runs applications with more than hundreds of thousands of lines of code. This is the long-term and gradual development of the "web", starting with a simple static page network and gradually evolving into one for various enrichments application of platforms. Not only that, but JS has become popular enough that it can be used outside of the browser environment. For example, implement a JS server with node .js. JS's "Run Anywhere" nature makes it an attractive option for cross-platform development. Nowadays, there are many developers only Full-stack programming is possible with JavaScript! In conclusion, we had a language designed for quick use that later evolved into a powerful tool for writing applications with millions of lines. Every language has it Weird, which feels weird or surprising. JavaScript's slightly rudimentary beginnings make it there A lot A weird thing. Some examples:
Most programming languages throw an error message when such an error occurs, and some do so during compilation (before any code runs). This weirdness is annoying when writing small programs, but it's easy to manage. When writing an application with hundreds or thousands of lines of code, these steady streams of surprises can be a serious problem. TypeScript: Static type checkerAs we mentioned earlier, some languages simply don't allow those wrong programs to run. Detecting errors in it without running code is called Static check 。 Depending on the kind of value being manipulated to determine what error and what is not an error, this is called static type Examine. TypeScript is based on before execution The type of the value Check the program for errors. It is Static Type Checker。 For example, based on // @errors: 2551
const obj = { width: 10, height: 15 };
const area = obj.width * obj.heigth; JavaScript typed supersetBut what does TypeScript have to do with JavaScript? grammarTypeScript is JavaScript superset : The JS syntax is therefore legal for TS. Syntax refers to the way we write text to form a program. For example, this code has one grammar Error because it is missing one // @errors: 1005
let a = (4 TypeScript does not treat any JavaScript code as an error. This means that you can put any valid JavaScript code in a TypeScript file without worrying about exactly how it is written. typeHowever, TypeScript is one Typing The superset of, meaning it adds rules on how to use different types of values. Previously about As another example, this JavaScript code can run in a browser Yes Print a value: console.log(4 / []); The syntax is legal for the program to print out // @errors: 2363
console.log(4 / []); You may It's true Trying to divide a number by an array, maybe just to see what happens, but most of the time, it's a programming error. TypeScript's type checker is designed to allow the right program to pass through while still catching as many common errors as possible. (Later, we'll learn how to configure TypeScript to control how strictly the inspection code is.) ) This may occur if you move some code from a JavaScript file to a TypeScript file Type error , depending on how the code is written. These may be real problems with the code, or TypeScript is too conservative. In this guide, we'll show you how to add various TypeScript syntax to eliminate such errors. Runtime behaviorTypeScript retains JavaScript's Runtime behavior 。 For example, the result of being divided by zero in JavaScript is This means that if you migrate code from JavaScript to TypeScript, even if TypeScript thinks the code has a type error guarantee Operates in the same way. Keeping the same behavior as the JavaScript runtime is a fundamental commitment of TypeScript. Because this means you can easily switch between two languages without worrying about some nuances that might stop the program from working. The type of eraseRoughly speaking, once TypeScript's compiler has done its job of inspecting the code, it does Erase type to generate the final "compiled" code. This means that once your code is compiled, the generated normal JS code has no type information. This also means that TypeScript will never change the program based on the type it infers behavior 。 Most importantly, although you may see type errors during compilation, the type system itself has nothing to do with how the program runs. Finally, TypeScript does not provide any additional runtime libraries. Your program uses the same standard library (or external library) as your JavaScript program. So you don't need to learn other frameworks specific to TypeScript. Learn JavaScript and TypeScriptWe often see questions like, "Should I learn JavaScript or TypeScript?" ”。 The answer is that you can't learn TypeScript without learning JavaScript! TypeScript shares JavaScript syntax and runtime behavior. Therefore, any knowledge of JavaScript can help you learn TypeScript. Programmers can use many, many resources to learn JavaScript. If you're writing TypeScript,No Ignore these resources. For example, with If you're searching for something like "how to sort a list in TypeScript," keep in mind: TypeScript is the JavaScript runtime with a compile-time type checker 。 Lists are sorted in TypeScript in the same way as in JavaScript. That's fine if you find resources that use TypeScript directly, but don't be limited to thinking you need TypeScript-specific answers when solving day-to-day problems with runtime tasks. NextThe following is a brief introduction to common syntax and tools in TypeScript. Here you can:
|
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.
Thanks for your work.
|
||
JavaScript(也称为ECMAScript)诞生时是一种简单的浏览器脚本语言。当它被发明时,它被期望用于网页中嵌入的简短代码片段。这些片段代码若超过几十行,在某种程度上是不常见的。因此,早期的 Web 浏览器执行此类代码的速度非常慢。但是,随着时间的流逝,JS 变得越来越流行,并且 Web 开发者开始使用它来创造交互式体验。 | ||
|
||
Web 浏览器开发者通过优化执行引擎(动态编译)和扩展可以完成的功能(添加API)来应对 JS 运用的增加,这反过来又使 Web 开发者更多地使用 JS。在现代网站上,你的浏览器经常运行跨数十万行代码的应用程序。这是“网络”的长期而渐进的发展,从一个简单的静态页面网络开始,逐渐演变成一个用于各种丰富 _应用程序_ 的平台。 |
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.
日益增加的 JS 的使用量?
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.
和扩展已完成的功能
extending what could be done with it 直接译成“已完成”吗?
|
||
不仅如此,JS已经变得足够流行,以至于可以在浏览器环境之外使用。例如用 node.js 实现 JS 服务器。JS “随处运行”的特性使其成为跨平台开发的颇具吸引力的选择。如今,有许多开发者 _只_ 使用 JavaScript 便可完成全栈编程! | ||
|
||
总之,我们有一种专为快速使用而设计的语言,后来发展为功能强大的工具,可以编写具有数百万行的应用程序。每种语言都有它的 _诡异之处_, 古怪或者惊异的,而 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.
诡异之处(不需要额外说明?不太好翻)
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.
有 很多 个 诡异之处
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.
后面 oddities and surprises 译成古怪或者惊异的也有点别扭...
@laosb PTAL. |
LGTM |
Merging because @Kingwl is a code-owner of all the changes - thanks! |
Translated this page to Chinese