Some of what’s covered in only 82 pages:
- TypeScript Concepts: Code Organization, Glossary, Compilation
- Visual Studio Extensions
- Type Safety
- Creating New Modules
- Loading Modules
- Unit Testing with TypeScript
A glimpse inside this ebook:
Concepts in TypeScript
Code organization I will begin by drawing some parallels between .NET and TypeScript in respect to code organization and language features. In some cases, the conventions are nearly identical, but there are also some interesting differences in both the naming conventions and the meaning of the various components used to compose your application.
Figure 1 demonstrates the structure of a TypeScript program, which is organized into a number of modules, each containing interfaces, classes, and variables. Each module should group related classes together and should have minimal dependencies on other modules in your program. Although you can create multidirectional dependencies and circular dependencies in TypeScript, I recommend that you avoid doing so, as it will make your program harder to maintain.
This program structure allows you to put your object-oriented programming skills into practice and makes it easy to use common design patterns to organize your program.
I will use the TypeScript naming conventions throughout this book, but feel free to read method when I use the term function, for example, if that is what you are more used to.
A TypeScript class is similar to a .NET class and can contain functions and variables with varying levels of visibility. In TypeScript you can use public and private visibility keywords on functions and variables.
A TypeScript class can extend one class and implement multiple interfaces.
A TypeScript function is like a .NET method, accepting arguments and returning a typed value or void. This is where the real logic will live in your program.
In TypeScript all properties and fields are variables, but with optional typing. By default, these variables behave in a similar manner to those declared in .NET using the var keyword, as the compiler will attempt to infer the type and then treat the variable as statically typed. In cases where the type cannot be inferred, the compiler doesn’t show an error as it would in .NET, but instead treats the variable as a dynamic type, which in TypeScript is indicated with the any keyword. I will discuss this in more detail in Chapter 3, “Type safety.”
Enumerations in TypeScript are similar to .NET enumerations. The experimental implementation in version 0.8 of TypeScript has been amended slightly in version 0.9.
If you try to use a feature that isn’t available in the version of ECMAScript you are targeting, the compiler will warn you to either avoid the feature or change the target version. I have included instructions on how to target ECMAScript 5 in Chapter 2, “Visual Studio.”
ECMAScript 5 was published in 2009 and is supported in all modern browsers. You can instruct the TypeScript compiler to target ECMAScript 5, which makes additional language features available, but your program may encounter problems in older browsers. The following browsers support all of the important features of ECMAScript 5; older versions of these browsers have only partial support:
- Internet Explorer 9 and above.
- Firefox 4 and above.
- Opera 12 and above.
- Safari 5.1 and above.
- Chrome 7 and above.
There is currently no release date planned for ECMAScript 6, and it doesn’t support all of the concepts in the TypeScript language.
TypeScript life cycle
To continue reading TypeScript Succinctly, download it from our Succinctly library.
If you like this blog post, we think you’ll also like the following free e-books: