Aurelia TypeScript Samples

TypeScript

In case your are wondering why you would want to look at using TypeScript, lets explore some of the features it provides.

JavaScript IS TypeScript

It is super easy to get started with TypeScript because JavaScript IS TypeScript. This means you can just rename your .js files to .ts files and you are off and running.

You will then immediately see TypeScript benefits before you've done anything to your code.

Type Inference

The TypeScript language service (which is leveraged by the IDE), can use type inference to make intelligent observations about your code and its expected types, before you ever add any type information yourself.

Some of the benefits are possible because there is additional information that the IDE tooling has about the code.

Type inference might be relatively simple, like picking up the type of a constant that is assigned to a variable at initialization, and flowing that type through a function return.

It may also be quite sophisticated like picking up a function signature from assignment to a known callback type, defined in a type definition file.

IntelliSense

When the IDE knows type information, it can offer statement completion reducing typos and also making platforms like Aurelia MUCH easier to learn and use (we'll see examples of this when we start developing our application).

The statement completion pop-up choices also includes any inline doc comments like descriptions, parameters and parameter descriptions and return types.

It makes it much easier for developers to explore, experiment with, and discover the features of an API.

Intelligent Refactoring

As an application grows in size, renaming and other refactoring operations become necessary. Without type information, error-prone search and replace options must be used, but with TypeScript, the language service knows where the renaming should occur and where it is a different identifier that happens to have the same name.

Code Generation

TypeScript type annotations evaporate when the code is compiled. The generated JavaScript is canonical JavaScript, well formatted, and what an expert would write to implement the corresponding patterns.

Type Definition Files

One very important capability of TypeScript, is the ability to wrap the API of an existing JavaScript library with defined types. This is done by creating a file with a .d.ts extension that declares the types a developer can expect from the API. Many, many JavaScript libraries have been wrapped by .d.ts files, created by the open source community and housed at DefinitelyTyped.

Each Aurelia repo has a corresponding .d.ts file, as seen here.