Skip to content

docs(cn): translate why-create-typescript into Chinese #169

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hexiaokang
Copy link

No description provided.

@ghost
Copy link

ghost commented Sep 16, 2022

CLA assistant check
All CLA requirements met.

@github-actions
Copy link
Contributor

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.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 16, 2022

Translation of Why Create Typescript.md

title: Why create TypeScript
layout: docs
permalink: /zh/why-create-typescript.html
oneline: Why create TypeScript

translatable: true

TypeScript is a JavaScript-based language created by MicroSoft. This post is a non-technical overview of what JavaScript is, how TypeScript extends JavaScript, and what problems TypeScript solves.

What is JavaScript?

Because TypeScript extends JavaScript, this is a good place to start. JavaScript is often used to create websites. When you create a website, it's written in three languages: HTML, CSS, and JavaScript (JS). In general, HTML defines what the page displays, CSS defines the style of the page, and JS defines the interactive behavior of the page.

We call people with these skills "front-end" developers. You can use these three languages to create pages in a browser (such as Safari, Firefox, Edge, or Chrome), and since the web is very popular in business and information sharing, there is a large demand for developers who are good at using these three languages.

Related to the "front-end" development role is a set of skills of the "back-end" developer who create a computer back-end service that communicates with a Web browser (by passing HTML/CSS/JS) or to another computer service (by sending data more directly). You don't need to use HTML, CSS, or JS to write this type of code, but it's usually the end result of your work because it happens to be displayed in a web browser.

What does a programming language do?

Programming languages are a way of communication between humans and computers. People spend a lot more time reading code than writing it—so developers create programming languages that excel at solving specific problems with small amounts of code. Here is an example using JavaScript:

var name = "Danger"
console.log("Hello, " + name)

The first line creates a variable (which is actually a container that can store other data), and then the second line outputs the text to the console (e.g. in DOS or a terminal window)"Hello, Danger"

JavaScript is designed to work as a scripting language, which means that the code starts at the head of the file and runs it line by line. To provide some comparison, the same behavior is implemented in Java below, which is built with different language constraints:

class Main {
  public static void main(String[] args) {
    String name = "Danger";
    System.out.println("Hello, " + name);
  }
}

The two code examples do the same thing, but the Java example comes with a lot of ambiguity that tells the computer what to do, for example class Main {public static void main(String[] args) {, and two extra curly braces }。 It also has semicolons at the end of some codes. There is nothing wrong with these programming languages, Java is designed to build something different from JavaScript, and this extra code makes sense within the constraints of building Java applications.

To understand the key points, we can focus on this highlighted line:

// JavaScript
var name = "Danger"

// Java
String name = "Danger";

Both lines of code declare a file named name , contains one "Danger" value.

In JavaScript, you use abbreviations var to declare the variable. At the same time, in Java, you need to declare the data type that a variable contains. In this example, one is included String A variable of type. (string is a programming term for a collection of characters.) they看起来像'这个'。 If you want to know more, this 5 minute video It's a great way to get started. )

Both variables contain a string type data, but the difference is that in Java the variable can only contain a string because this is what we defined when we created the variable. In JS, variables can be changed to any value, such as a number or a list of dates.

Please see:

// Before in JS
var name = "Danger"
// Also OK
var name = 1
var name = false
var name = ["2018-02-03", "2019-01-12"]

// Before in Java
String name = "Danger";
// Not OK, the code wouldn't be accepted by Java
String name = 1;
String name = false
String name = new String[]{"2018-02-03", "2019-01-12"};

These trade-offs make sense in the context of when these languages were created in 1995. JavaScript was originally designed as a lightweight programming language for handling simple interactions within websites. Java was created specifically for developing complex applications that can run on any computer. They are used to build codebases of different sizes, so programmers are required to write different types of code.

Java requires programmers to be more explicit about their variable values because they want to build more complex programs. JavaScript, on the other hand, opts for legibility improvements by omitting details, and expects a much smaller codebase.

What is TypeScript?

TypeScript is a programming language — it includes all JavaScript and has more syntax features. Use our example above to compare the "Hello, Danger" script in JavaScript and TypeScript:

// JavaScript
var name = "Danger"
console.log("Hello, " + name)

// TypeScript
var name = "Danger"
console.log("Hello, " + name)

// 是的,你没有错过任何东西,他们之间没有差异

Since TypeScript's goal is to extend JavaScript only, we see that current JavaScript code can also run in TypeScript. TypeScript is an extension to JavaScript designed to help you know more clearly what type of data is used in your code, a bit like Java.

This is the same example, but uses TypeScript to more explicitly define what type a variable is:

var name: string = "Danger"
console.log("Hello, " + name)

This extra : string Let the developer be sure name Can only be one string type data. Labeling variables in this way also gives TypeScript a chance to verify that they match. This is useful because tracking the type change of a variable value seems easy when one or two, but once it starts to reach hundreds, it needs to be tracked a lot. Writing types helps programmers feel more confident in their code because the type system catches errors.

In simple terms, we call these annotations a "type system". Hence the name Type Script。 One of TypeScript's slogans is "Extensible JavaScript," which states that these additional type annotations can help you develop larger projects. This is because you can verify the correctness of the code beforehand. This means you can focus less on whether each change to your code will affect the rest of your code.

In the 90s, maybe until 5-10 years ago, it was fine to have no type system in JavaScript applications, because the current creation of applications is limited to the front-end part of the website in terms of size and complexity. Today, however, JavaScript is used almost everywhere and can be built into almost any application that runs on a computer. A large number of mobile and desktop applications use JavaScript and web technologies.

These projects are quite complex to create and understand, and adding a type system greatly reduces the complexity of modifying these applications.

What problem does TypeScript solve?

Typically, you can make sure there are no errors in your code by writing automated tests, then manually verify that the code works as you expect, and finally have another person verify that it is correct.

There aren't many companies the size of Microsoft, but many of the problems with writing JavaScript in a large codebase are the same. Many JavaScript applications consist of hundreds or thousands of files. Changes to a single file can affect the code of many other files, just as throwing a pebble into a pond causes ripples to spread to the shore.

Verifying relationships between each part of a project is time-consuming, and using a type-checking language like TypeScript can be automated and provide immediate feedback during development.

These features of TypeScript help developers feel more confident in their code and save a lot of time verifying that they don't accidentally affect the project.

Generated by 🚫 dangerJS against 5ead222

@awxiaoxian2020
Copy link
Contributor

The path seems wrong...

@awxiaoxian2020
Copy link
Contributor

The source file is https://github.com/microsoft/TypeScript-Website/blob/v2/packages/typescriptlang-org/src/templates/pages/why-create-typescript.tsx

Not .md file

I don't know how to support translations.

cc: @orta

@hexiaokang
Copy link
Author

Co-authored-by: Steven Ding <1139274654@qq.com>
@microsoft-github-policy-service

@hexiaokang please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
and conveys certain license rights to Microsoft Corporation and its affiliates (“Microsoft”) for Your
contributions to Microsoft open source projects. This Agreement is effective as of the latest signature
date below.

  1. Definitions.
    “Code” means the computer software code, whether in human-readable or machine-executable form,
    that is delivered by You to Microsoft under this Agreement.
    “Project” means any of the projects owned or managed by Microsoft and offered under a license
    approved by the Open Source Initiative (www.opensource.org).
    “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any
    Project, including but not limited to communication on electronic mailing lists, source code control
    systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of
    discussing and improving that Project, but excluding communication that is conspicuously marked or
    otherwise designated in writing by You as “Not a Submission.”
    “Submission” means the Code and any other copyrightable material Submitted by You, including any
    associated comments and documentation.
  2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any
    Project. This Agreement covers any and all Submissions that You, now or in the future (except as
    described in Section 4 below), Submit to any Project.
  3. Originality of Work. You represent that each of Your Submissions is entirely Your original work.
    Should You wish to Submit materials that are not Your original work, You may Submit them separately
    to the Project if You (a) retain all copyright and license information that was in the materials as You
    received them, (b) in the description accompanying Your Submission, include the phrase “Submission
    containing materials of a third party:” followed by the names of the third party and any licenses or other
    restrictions of which You are aware, and (c) follow any other instructions in the Project’s written
    guidelines concerning Submissions.
  4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else
    for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your
    Submission is made in the course of Your work for an employer or Your employer has intellectual
    property rights in Your Submission by contract or applicable law, You must secure permission from Your
    employer to make the Submission before signing this Agreement. In that case, the term “You” in this
    Agreement will refer to You and the employer collectively. If You change employers in the future and
    desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement
    and secure permission from the new employer before Submitting those Submissions.
  5. Licenses.
  • Copyright License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the
    Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute
    the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third
    parties.
  • Patent License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under
    Your patent claims that are necessarily infringed by the Submission or the combination of the
    Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and
    import or otherwise dispose of the Submission alone or with the Project.
  • Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement.
    No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are
    granted by implication, exhaustion, estoppel or otherwise.
  1. Representations and Warranties. You represent that You are legally entitled to grant the above
    licenses. You represent that each of Your Submissions is entirely Your original work (except as You may
    have disclosed under Section 3). You represent that You have secured permission from Your employer to
    make the Submission in cases where Your Submission is made in the course of Your work for Your
    employer or Your employer has intellectual property rights in Your Submission by contract or applicable
    law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You
    have the necessary authority to bind the listed employer to the obligations contained in this Agreement.
    You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS
    REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES
    EXPRESSLY STATED IN SECTIONS 3, 4, AND 6, THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS
    PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
    NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  2. Notice to Microsoft. You agree to notify Microsoft in writing of any facts or circumstances of which
    You later become aware that would make Your representations in this Agreement inaccurate in any
    respect.
  3. Information about Submissions. You agree that contributions to Projects and information about
    contributions may be maintained indefinitely and disclosed publicly, including Your name and other
    information that You submit with Your Submission.
  4. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and
    the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County,
    Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to
    exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all
    defenses of lack of personal jurisdiction and forum non-conveniens.
  5. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and
    supersedes any and all prior agreements, understandings or communications, written or oral, between
    the parties relating to the subject matter hereof. This Agreement may be assigned by Microsoft.

Co-authored-by: Steven Ding <1139274654@qq.com>
@microsoft-github-policy-service

@hexiaokang the command you issued was incorrect. Please try again.

Examples are:

@microsoft-github-policy-service agree

and

@microsoft-github-policy-service agree company="your company"

Copy link

@stevending1st stevending1st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@microsoft-github-policy-service

@hexiaokang the command you issued was incorrect. Please try again.

Examples are:

@microsoft-github-policy-service agree

and

@microsoft-github-policy-service agree company="your company"

@hexiaokang
Copy link
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants