Search code examples
typescript

How to write an interface represents a tuple type in TypeScript?


Glad to see the release of TypeScript 1.3, but how to write an interface represents a tuple type?

E.g.

var data: [string, number, number];

How to write an interface IData so that I would be able to do the same thing by writing

var data: IData;

Solution

  • I know this is an old question, but I think you can accomplish what you want with the following:

    type IData = [string, number, number];
    

    then

    var data: IData;
    

    You can see this in this TypeScript Playground example