-
Notifications
You must be signed in to change notification settings - Fork 130
translate TypeScript Tooling in 5 minutes.md in zh-CN #181
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
base: main
Are you sure you want to change the base?
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 TypeScript Tooling in 5 minutes.mdtitle: 5 minutes to learn about the TypeScript tool translatable: trueLet's start with Install TypeScriptThere are two main ways to use TypeScript in your projects:
Visual Studio 2017 and Visual Studio 2015 Update 3 include TypeScript language support by default, but not the TypeScript compiler If you don't have TypeScript installed in Visual Studio, you can do it hereDownload it。 Using npm: > npm install -g typescript Build your first TypeScript fileIn the editor, in // @noImplicitAny: false
function greeter(person) {
return "Hello, " + person;
}
let user = "Jane User";
document.body.textContent = greeter(user); Compile your codeWe used On the command line, run the TypeScript compiler: tsc greeter.ts One is generated Now we can start using some of the new tools that TypeScript offers. toward function greeter(person: string) {
return "Hello, " + person;
}
let user = "Jane User";
document.body.textContent = greeter(user); Type annotationType annotations in TypeScript are a lightweight way to constrain the type of a function or variable. In this example, we indicated that we want to call the greeter function with a single string parameter. Then we try to call greeter by passing array parameters instead: // @errors: 2345
function greeter(person: string) {
return "Hello, " + person;
}
let user = [0, 1, 2];
document.body.textContent = greeter(user); When recompiling, you will see an error: error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'string'. Again, try to remove all the arguments called by greeter, and TypeScript will tell you that you called this function, but the number of arguments is not as expected. In both cases, TypeScript can provide static analysis based on the structure of the code and the type comments provided. Note that despite the error, though interfaceLet's refine our example further. Here we use one interface Person {
firstName: string;
lastName: string;
}
function greeter(person: Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
let user = { firstName: "Jane", lastName: "User" };
document.body.textContent = greeter(user); kindFinally, let's use Here, we will create one with a constructor and several public fields Another thing to note is that it is used on the parameters of the constructor class Student {
fullName: string;
constructor(
public firstName: string,
public middleInitial: string,
public lastName: string
) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function greeter(person: Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
let user = new Student("Jane", "M.", "User");
document.body.textContent = greeter(user); rerun Run your TypeScript web applicationNow in <!DOCTYPE html>
<html>
<head>
<title>TypeScript Greeter</title>
</head>
<body>
<script src="greeter.js"></script>
</body>
</html> Open in a browser Tip: Open in Visual Studio Type hints work together through JavaScript editor tools, such as Visual Studio or TypeScript's built-in compilation platform, TypeScript Playground. |
@microsoft-github-policy-service agree [company="{zzall}"] |
@microsoft-github-policy-service agree |
|
||
小提示:在Visual Studio中打开`greeter.ts`,或将代码复制到[TypeScript Playground](https://www.typescriptlang.org/play)中。 | ||
您可以将光标悬停在标识符上来查看其类型。 | ||
请注意,在某些情况下,类型会自动为您推到。 |
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.
请注意,在某些情况下,类型会自动为您推到。 | |
请注意,在某些情况下,类型会自动为您推导。 |
translate TypeScript Tooling in 5 minutes.md in zh-CN