• Complain

Steve Fenton - Pro TypeScript: Application-Scale JavaScript Development

Here you can read online Steve Fenton - Pro TypeScript: Application-Scale JavaScript Development full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2014, publisher: Apress, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Steve Fenton Pro TypeScript: Application-Scale JavaScript Development
  • Book:
    Pro TypeScript: Application-Scale JavaScript Development
  • Author:
  • Publisher:
    Apress
  • Genre:
  • Year:
    2014
  • Rating:
    3 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 60
    • 1
    • 2
    • 3
    • 4
    • 5

Pro TypeScript: Application-Scale JavaScript Development: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Pro TypeScript: Application-Scale JavaScript Development" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

JavaScript is everywhere, both as a pure language and in popular libraries like Angular, jQuery and Knockout, but users of modern object-oriented languages like Java and C# often find JavaScript frustrating to use and hard to extend to large-scale applications. TypeScript is an innovative open source language from Microsoft that combines powerful language features and enhanced tooling support with the key attractions of JavaScript as a flexible, dynamic language that can run in any browser and on any operating system. Pro TypeScript tells you everything you need to know about this exciting new language and how to use it in your applications.

Starting with an introduction to the language and its features, the book takes you through some of the major features of TypeScript in depth, from working with the type system through object-orientation to understanding the runtime and the TypeScript compiler. The book then covers some of the factors you need to consider when running a TypeScript application in the browser, including interacting with the DOM, making asynchronous requests, and working with useful browser APIs, followed by a demonstration of server-side TypeScript using the popular Node.js framework.

Because TypeScript compiles to plain JavaScript, exception handling, memory management and garbage collection can differ depending on where you run your program, so these topics get a chapter to themselves. Youll also find out how to include popular JavaScript frameworks in your applications, so you can combine the benefits of TypeScript with some of the best JavaScript code thats already out there waiting to be used. The final chapter gives an overview of automated testing for TypeScript applications.

Pro TypeScript offers a balanced and practical guide to a language that will transform your experience of JavaScript development.

Steve Fenton: author's other books


Who wrote Pro TypeScript: Application-Scale JavaScript Development? Find out the surname, the name of the author of the book and a list of all author's works by series.

Pro TypeScript: Application-Scale JavaScript Development — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Pro TypeScript: Application-Scale JavaScript Development" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Steve Fenton 2014
Steve Fenton Pro TypeScript 10.1007/978-1-4302-6790-4_1
1. TypeScript Language Features
Steve Fenton 1
(1)
Basingstoke, United Kingdom
What if we could strengthen JavaScript with the things that are missing for large scale application development, like static typing, classes [and] modules... thats what TypeScript is about.
Anders Hejlsberg
TypeScript is a superset of JavaScript. That means that the TypeScript language includes the entire JavaScript language plus a collection of useful additional features. This is in contrast to the various subsets of JavaScript and the various lint tools that seek to reduce the available features to create a smaller language with fewer surprises. This chapter will introduce you to the extra language features, starting with simple type annotations and progressing to more advanced features and structural elements of TypeScript. This chapter doesnt cover the features included in the ECMAScript 5 language specification so if you need a refresher on JavaScript take a look at Appendix 1.
The important thing to remember is that all of the standard control structures found in JavaScript are immediately available within a TypeScript program. This includes:
  • Control flows
  • Data types
  • Operators
  • Subroutines
The basic building blocks of your program will come from JavaScript, including if statements, switch statements, loops, arithmetic, logical tests, and functions. This is one of the key strengths of TypeScriptit is based on a language (and a family of languages) that is already familiar to a vast and varied collection of programmers. JavaScript is thoroughly documented not only in the ECMA-262 specification, but also in books, on developer network portals, forums, and question-and-answer websites.
Each of the language features discussed in this chapter has short, self-contained code examples that put the feature in context. For the purposes of introducing and explaining features, the examples are short and to the point; this allows the chapter to be read end-to-end. However, this also means you can refer back to the chapter as a reference later on. Once you have read this chapter, you should know everything you will need to understand the more complex examples described throughout the rest of the book.
JavaScript Is Valid TypeScript
Before we find out more about the TypeScript syntax, it is worth stressing this important fact: All JavaScript is valid TypeScript, with just a small number of exceptions, which are explained below. You can take existing JavaScript code, add it to a TypeScript file, and all of the statements will be valid. There is a subtle difference between valid code and error-free code in TypeScript; because, although your code may work, the TypeScript compiler will warn you about any potential problems it has detected.
If you transfer a JavaScript listing into a TypeScript file you may receive errors or warnings even though the code is considered valid. A common example comes from the dynamic type system in JavaScript wherein it is perfectly acceptable to assign values of different types to the same variable during its lifetime. TypeScript detects these assignments and generates errors to warn you that the type of the variable has been changed by the assignment. Because this is a common cause of errors in a program, you can correct the error by creating separate variables, by performing a type assertion, or by making the variable dynamic. There is further information on type annotations later in this chapter, and the type system is discussed in detail in .
Unlike some compilers that will only create output where no compilation errors are detected, the TypeScript compiler will still attempt to generate sensible JavaScript code. The code shown in Listing 1-1 generates an error, but the JavaScript output is still produced. This is an admirable feature, but as always with compiler warnings and errors, you should correct the problem in your source code and get a clean compilation. If you routinely ignore warnings, your program will eventually exhibit unexpected behavior. In some cases, your listing may contain errors that are so severe the TypeScript compiler wont be able to generate the JavaScript output.
Listing 1-1.Using JavaScripts with statement
// Not using with
var radius = 4;
var area = Math.PI * radius * radius;
// Using with
var radius = 4;
with (Math) {
var area = PI * radius * radius;
}
Caution
The only exceptions to the all JavaScript is valid TypeScript rule are the with statement and vendor specific extensions, such as Mozillas const keyword.
The JavaScript with statement in Listing 1-1 shows two examples of the same routine. Although the first calls Math.PI explicitly, the second uses a with statement, which adds the properties and functions of Math to the current scope. Statements nested inside the with statement can omit the Math prefix and call properties and functions directly, for example the PI property or the floor function.
At the end of the with statement, the original lexical scope is restored, so subsequent calls outside of the with block must use the Math prefix.
The with statement is not allowed in strict mode in ECMAScript 5 and in ECMAScript 6 classes and modules will be treated as being in strict mode by default. TypeScript treats with statements as an error and will treat all types within the with statement as dynamic types. This is due to the following:
  • The fact it is disallowed in strict mode.
  • The general opinion that the with statement is dangerous.
  • The practical issues of determining the identifiers that are in scope at compile time.
So with these minor exceptions to the rule in mind, you can place any valid JavaScript into a TypeScript file and it will be valid TypeScript. As an example, here is the area calculation script transferred to a TypeScript file.
Note
The ECMAScript 6 specification, also known as ES6 Harmony, represents a substantial change to the JavaScript language. The specification is still under development at the time of writing.
In Listing 1-2, the statements are just plain JavaScript, but in TypeScript the variables radius and area will both benefit from type inference. Because radius is initialized with the value , it can be inferred that the type of radius is number . With just a slight increase in effort, the result of multiplying Math.PI , which is known to be a number , with the radius variable that has been inferred to be a number , it is possible to infer the type of area is also a number .
Listing 1-2.Transferring JavaScript in to a TypeScript file
var radius = 4;
var area = Math.PI * radius * radius;
With type inference at work, assignments can be checked for type safety. Figure .
Figure 1-1 Static type checking Variables TypeScript variables must - photo 1
Figure 1-1.
Static type checking
Variables
TypeScript variables must follow the JavaScript naming rules. The identifier used to name a variable must satisfy the following conditions.
The first character must be one of the following:
  • an uppercase letter
  • a lowercase letter
  • an underscore
  • a dollar sign
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Pro TypeScript: Application-Scale JavaScript Development»

Look at similar books to Pro TypeScript: Application-Scale JavaScript Development. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Pro TypeScript: Application-Scale JavaScript Development»

Discussion, reviews of the book Pro TypeScript: Application-Scale JavaScript Development and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.