Facilitating the spread of knowledge and innovation in professional software development



Choose your language

InfoQ Homepage News TypeScript 2.2 Adds New Object Type, Better Mixin Support, and More

TypeScript 2.2 Adds New Object Type, Better Mixin Support, and More

This item in japanese


Scheduled to be released sometime in February, TypeScript 2.2 has reached RC status. Besides a new JSX emit mode for React Native, it also includes a new object type to represent non-native types, better support for mixins and composable classes, and more.

The new object type provided by TypeScript 2.2 makes it possible to specify method signatures that only accept non-primitive types. This is the case, e.g., with the Object.getPrototypeOf, Object.create etc., which can syntactically accept any kind of object but will throw an exception if they are passed, e.g., a string or a number. The object type allows to catch those kind of misuses at compile-time:

  function mapObject(obj: object): object { /* ... */ }
  mapObject('string'); // type error

TypeScript 2.2 also adds more flexibility to the creation of mixins and composable types. For example, you can now create a function that takes the constructor of a Point object, declares a new class that extends Points by adding a timestamp to it, and returns a new TimestampedPoint mixin class, which can be instantiated or extended:

class Point {

export type Constructable = new (...args: any[]) => object;
export function Timestamped<BC extends Constructable>(Base: BC) {
    return class extends Base {
        timestamp = new Date();

const TimestampedPoint = Timestamped(Point);
const p = new TimestampedPoint(10, 10);

class SpecialPoint extends Timestamped(Point) {
  z:  number;
  constructor(x: number, y: number, z: number) {


TypeScript has long supported the use of JSX, an XML-like language extension without any defined semantics which aims to represents tree structures with attributes. A typical, although not exclusive, usage of JSX is to describe UI components. Up to version 2.1, TypeScript has been able able to handle JSX expressions in tsx files through two specific emit modes: preserve, which retains the JSX expressions so they can be consumed by a later stage, and react, which creates a js file that uses React.createElement. New in version 2.2 is a new react-native mode, which leaves all JSX expressions intact, but generates a js file, as it is required by React Native’s loader.

TypeScript 2.2rc includes more notable changes, such as:

You can try out TypeScript 2.2rc by running:

npm install -g typescript@rc
We need your feedback

How might we improve InfoQ for you

Thank you for being an InfoQ reader.

Each year, we seek feedback from our readers to help us improve InfoQ. Would you mind spending 2 minutes to share your feedback in our short survey? Your feedback will directly help us continually evolve how we support you.

Take the Survey

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p


Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.