Benoit Benoit - 1 year ago 151
TypeScript Question

How to declare an interface for dictionary?

I wish to add definition for a plugin I love and I wish to know how I can define the type to allow this without use the type any.

I will use the property like this:

views: {
'list.view1': {
dropPagingCap: 20,
list_infiniteScroll: true,
list_selectable: 'multi'
'list.view2': {
dataSource: function(options, callback){ ... },
dropPagingCap: 30,
list_selectable: true

I have tried this, but the library except an object {}, not an array []

interface IFuelUxRepeaterViews {
[index: string]: IFuelUxRepeaterParametersBase | IFuelUxRepeaterListParameter | IFuelUxRepeaterTumbnailParameter | IFuelUxRepeaterAllParameter;

I dont know how to name this javascript type of declaration to find something on google.

Thanks to point me to the answer or any duplicate on StackOverflow.

ps. Excuse my bad english, im french :s

Answer Source

From your code example it seems like your views can be represented using the following interface:

interface IFuelUxRepeaterViews {
    [index: string]: {
        dropPagingCap: number;
        dataSource?: (options: any, cb: () => void) => void;
        list_infiniteScroll?: boolean;
        list_selectable?: string | boolean;   
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download