Author: sanqunbao


Dojo Object Stores

Dojo 1.6 introduces a new data store API called Dojo Object Store. This new store API is based on the HTML5 IndexedDB object store API and is designed to greatly simplify and ease the interaction and construction of Dojo stores. Update: dstore is developing as a successor to Dojo object stores, so if you are […]


Introduction to Enums in TypeScript

Enums are a TypeScipt data type that allow the organization of number-based collections of unique identifiers. Here’s how to define a simple enum: enum Transport { train, bus, bike, car } let myTransport = Transport.bus; console.log(myTransport); // 1 You can access an enum value by it’s number value or by the string that’s associated with […]


Introduction to Interfaces in TypeScript

TypeScript helps us keep a contract with our vales by allowing us to define fine-grained type checking for them. Interfaces is the primary mechanism in TypeScript to accomplish that. Let’s say for example that we have the following code where we define two users: const user1 = { id: 1, firstName: ‘John’, lastName: ‘Doe’, proUser: […]


Object Rest and Spread in TypeScript

TypeScript 2.1 brings us object rest & spread to easily destructure, make shallow copies and merge objects into new ones. Object Spread Create shallow copy of objects: const names = {cat: ‘Bob’, dog: ‘Fred’, alligator: ‘Benedict’}; const newNames = { …names }; console.log(; // Bob You can merge multiple objects into a new object: const […]


String Literal Types in TypeScript

In TypeScript, string literal types let you define types that only accept a defined string literal. They are useful to limit the possible string values of variables. It’s better explained with short code samples, so here are examples of how to define and use string literal types: let pet: ‘cat’; pet = ‘cat’; // Ok […]


Union Types in TypeScript

In TypeScript you can use union types to describe values that can be of more than one type. It therefore allows to avoid using any. Define union types with the | character to separate the different possible types. For example, let’s say a function definition uses parameters that describe values that can be either strings […]