-
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
fix: correct typos #212
fix: correct typos #212
Conversation
Thanks for the PR! This section of the codebase is owned by @khaosdoctor and @danilofuchs - if they write a comment saying "LGTM" then it will be merged. |
Translation of TS for the New Programmer.mdtitle: TypeScript for the New Programmer oneline: Learn TypeScript from scratchCongratulations on choosing TypeScript as one of your first languages - you're already making good decisions! You may have heard that TypeScript is a "flavor" or a "variant" of JavaScript. The relationship between TypeScript (TS) and JavaScript (JS) is unique among modern programming languages, so learning more about this relationship will help you understand how TypeScript adds to JavaScript. What is JavaScript? A Brief HistoryJavaScript (also known as ECMAScript) began its life as a simple scripting language for browsers. At the time it was invented, it was always expected to be used for small snippets of code embedded on a web page - writing more than a dozen lines of code would be unusual. Therefore, young browsers of the time executed such code very slowly. However, over time, JS became more and more popular and web developers began using it to create interactive experiences. Web browser developers responded to this increased use of JS by optimizing their engines by optimizing their engines (dynamic compilation) and extending what could be done with it (adding APIs), which in turn made web developers use it even more. On modern websites, your browser is often running applications that have hundreds of thousands of lines of code. This is the long and gradual growth of the web, starting as a simple network of static pages and evolving into a platform for Applications rich of all kinds. More than that, JS has become popular enough to be used outside the context of browsers, such as implementing JS servers using node.js. JS's "run anywhere" nature makes it an attractive choice for cross-platform development. There are many developers these days who use only JavaScript to program your entire suite of applications! To summarize, we have a language that was developed for quick uses and then grew into a complete tool for writing applications with millions of lines. Every language has its own Individuals - uniqueness and surprises and the humble beginning of JavaScript makes it many These. Some examples:
Most programming languages would throw an error when this type of situation occurred, some would do so at compile time - before any code was running. When writing small programs, such individualities are annoying but manageable; when writing applications with hundreds or thousands of lines of code, these constant surprises are a serious problem. TypeScript: A Static Type CheckerWe said before that some languages would not allow these programs to bug or run. Error detection without code execution is called static check. Determining what is an error and what is not based on the types of values being operated is called static verification of Types. TypeScript checks a program for errors before it runs and does so based on the kinds of values, is a static type tester. For example, the last example above has an error because of the kind from // @errors: 2551
const obj = { width: 10, height: 15 };
const area = obj.width * obj.heigth; A JavaScript Typed SupersetHow does TypeScript re-trigger with JavaScript then? SyntaxTypeScript is a language that is a Superset of JavaScript: JS syntax is therefore valid in TS. Syntax refers to the way we write text to form a program. For example, this code has a syntax because there's a lack of // @errors: 1005
let a = (4 TypeScript does not consider any JavaScript code to be an error because of its syntax. This means you can take any JavaScript functional code and put it into a TypeScript file without worrying about how it's written. TypesHowever, TypeScript is a superset Typed, meaning that you add rules about how different types of values can be used. The previous error about As another example, this is JavaScript code that you can run in your browser and it will display a value: console.log(4 / []); This syntactically cool program displays // @errors: 2363
console.log(4 / []); It's possible that you actually Want divide a number by an array, maybe just to see what happens, but most of the time this is a programming error. The TypeScript type checker is designed to allow correct programs while preventing as many common errors as possible. (Later, we'll learn about settings that you can use to configure how strictly TypeScript checks your code.) If you move some code from a JavaScript file to a TypeScript file, you can see type errors depending on how the code is written. These can be legitimate problems with code or TypeScript being overconservative. Through this guide we will demonstrate how to add various TypeScript syntaxes to eliminate such errors. Runtime BehaviorTypeScript is also a programming language that preserves the runtime behavior javascript. For example, dividing by zero in JavaScript produces This means that you move JavaScript code from TypeScript, it is secure that will run the same way that TypeScript thinks the code has type errors. Maintaining the same behavior at runtime as JavaScript is a fundamental promise of TypeScript because it means that you can easily transition between two languages without worrying about subtle differences that can cause your program to stop working. Deleted TypesRoughly speaking, once the TypeScript compiler has finished checking your code, it Erases the types to produce the resulting "compiled" code. This means that once your code is compiled, the pure Result JS code has no type information. This also means that TypeScript never changes the behaviour program based on the types it infers. The end of this is that while you see type errors during compilation, the type system itself has no influence on how your program works when it runs. Finally, TypeScript does not provide any additional runtime library. Your programs will use the same standard (or external) libraries as JavaScript programs, so there are no additional TypeScript-specific tools to learn. Learning JavaScript and TypeScriptWe often see the question "Should I learn JavaScript or TypeScript?". The answer is that you can't learn TypeScript without learning JavaScript! TypeScript shares syntax and runtime behavior with JavaScript, so anything you want to learn about JavaScript will be helping you learn TypeScript at the same time. There are many, many features available for programmers to learn JavaScript; you No you should ignore these features if you are writing TypeScript. For example, there are about 20 times as many questions in StackOverflow that are marked with If you find yourself looking for something like "how to organize a list in TypeScript," remember: TypeScript is the JavaScript execution environment with build-time type checker. The way you organize a list in TypeScript is the same in JavaScript. If you find a feature that uses TypeScript directly this is great too, but don't just think that you need specific TypeScript answers to day-to-day questions about how to achieve execution environment tasks. Next StepsThis was a short summary of the syntax and tools used in TypeScript in day-to-day life. From 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.
LGTM
Hi @cfigueiroa, for some reason the branch was not merged by the bot. |
done |
LGTM |
Merging because @danilofuchs is a code-owner of all the changes - thanks! |
No description provided.