![]() $ npx tsc -target es6 hello.ts Configuring the TypeScript Compiler After running the following command, hello.js will contain a template literal. The target ECMAScript version can be configured using the -target command line flag as shown below. This is because tsc defaults to outputting ECMAScript version 3 compatible code. However, note that the template literal has been replaced by string concatenation. ![]() In this example, the input was standard JavaScript, so the output looks nearly identical. These commands will create a new hello.js file containing the compiler output shown below. ts extension, and run the TypeScript compiler, tsc: $ mv hello.js hello.ts ![]() Next, rename the JavaScript file to have a. To illustrate the simplicity of getting started with TypeScript, create a file named hello.js containing the following code: 'use strict' However, TypeScript's syntax is a strict superset of JavaScript, meaning that it can be integrated into existing projects immediately. TypeScript markets itself as "JavaScript that scales." In reality, TypeScript is yet another compile-to-JavaScript language in the same vein as CoffeeScript, ClojureScript, and numerous others. The code samples throughout this post assume Node 8.9.0 or greater. This post is not intended to be a comprehensive language reference, but will point interested readers in the right direction to learn more. The remainder of this blog post introduces the TypeScript language, including some of its advantages and disadvantages compared to vanilla JavaScript. That is where TypeScript comes into the picture. The fact that a JavaScript variable can hold any data type at any point during execution is an extremely common source of bugs in large applications. Newer incarnations of Node.js contain async/ await, which greatly simplifies working with asynchronous code, but static typing is still a pain point for some developers migrating from compiled languages. Typically, the two largest hurdles these would-be JavaScript developers face are the asynchronous programming paradigm, and the lack of static typing. As Node.js continues to increase in popularity, the platform is seeing an influx of developers from other languages such as Java and C#.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |