TypeScript: Can I declare that an interface may have any number of further attributes?

typescript

Solution

The closest syntax is as follows:

interface MyInterface {
    [index: string]: any;
    num: number;
    func: Function;
}

var a: MyInterface = {
    num: 123,
    func: function () {},
    prop1: 'Hello',
    prop2: 'World'
};

The type "any" must be used because the properties "num" and "func" are not strings:

While index signatures are a powerful way to describe the array and 'dictionary' pattern, they also enforce that all properties match their return type.

Source: the TS Handbook.

Problem

Is it possible to express "instances of this interface have a number called 'num', a function called 'func' and may have any number of more attribute with unspecified name that are of type string" in TypeScript? I imagine it might look like this: ``` interface MyInterface { num: number; func: Function; *: string; } ``` You probably want to tell me that this is poor API-Design, but I am writing definition files for a 3rd party library and I cannot change that :-(.

Original source