|
Note
In accordance Benpian implementation steps, you can in the "Windows", "OS X" operating system, developed using Visual Studio Code TypeScript.
Foreword
In order to solve JavaScript: Missing object-oriented syntax, the lack of error checking during compilation ... and so on. Microsoft provides an open source TypeScript language, allowing developers to use object-oriented code written TypeScript, followed by TypeScript code compiler will be compiled into JavaScript code, you can build a JavaScript compiled checking code to provide a platform use.
This article describes how to "Windows", "OS X" operating system, through the Visual Studio Code TypeScript development tool, so that no budget purchase the developer tools, it is possible to learn TypeScript syntax. Mainly as to leave a record, but also want to help the needy developers.
Install Node.js
First install Node.js, follow-up can be installed using the NPM TypeScript Compiler tool. The Node.js installer, Node.js can be downloaded from the official website.
Installation TypeScript Compiler
Bahrain Node.js, then you can use to install TypeScript Compiler NPM, then you can see through to the Compiler will TypeScript compiled into JavaScript. Developers use the Command Prompt (or terminal), enter the following command to complete the TypeScript Compiler installation.
npm install -g typescript
Update TypeScript Compiler
View a step on the installed TypeScript Compiler, you will find that the installed version is 1.4.1. But because the next steps required to Version 1.5.0 added new features, developers also use the Command Prompt (or terminal), enter the following command to update TypeScript Compiler to version 1.5.0 and above.
npm update -g typescript
Remove an environment variable (Windows only)
Computer Some developers may have been previously installed TypeScript tools, these tools will be added to the installation path TypeScript Compiler in the Windows environment variable. In order to unify the use of NPM to manage TypeScript Compiler version, developers need to manually remove the installation path TypeScript Compiler from the environment variable:
C: \ Program Files (x86) \ Microsoft SDKs \ TypeScript \ 1.0 \
Install Visual Studio Code
Bahrain TypeScript Compiler, and then install Visual Studio Code, after the program code will be able to develop TypeScript through Visual Studio Code. Visual Studio Code and installer can be downloaded from the Visual Studio Code official website.
Development TypeScript
Establish Workspace
After the installation is complete, open the Visual Studio Code, and select a folder as a development TypeScript working folder (Workspace).
Establish tsconfig.json
Then add a new file in the Workspace "tsconfig.json", and enter the following JSON set parameters.
{
"CompilerOptions": {
"Target": "es5",
"NoImplicitAny": false,
"Module": "amd",
"RemoveComments": false,
"SourceMap": true
}
}
Establish .settings \ tasks.json
Workspace also joined again in a new folder ".settings" and add a new file "tasks.json" in this folder, then enter the following JSON set parameters.
{
"Version": "0.1.0",
"Command": "tsc",
"IsShellCommand": true,
"ShowOutput": "always",
"Args": [ "-p", "."],
"ProblemMatcher": "$ tsc"
}
Development main.ts
After completing the above steps to add a new file in the Workspace "main.ts", and enter the following TypeScript code.
class Greeter {
data: string;
constructor (data: string) {
this.data = data;
}
run () {
alert (this.data);
}
}
window.onload = () => {
var greeter = new Greeter ( "Clark");
greeter.run ();
};
Finally, press the shortcut key "Ctrl + Shift + B", you can see Visual Studio Code compiled TypeScript, and outputs the corresponding JavaScript file: main.js.
var Greeter = (function () {
function Greeter (data) {
this.data = data;
}
Greeter.prototype.run = function () {
alert (this.data);
};
return Greeter;
}) ();
window.onload = function () {
var greeter = new Greeter ( "Clark");
greeter.run ();
};
// # SourceMappingURL = main.js.map |
|
|
|