Skip to content

String map compile error #573

@andrewvarga

Description

@andrewvarga

Not sure if this is an error or just me not understanding it:

interface ITestInterface
{
    // this doesn't compile
    myMap: {
        [id:string]:string;
    }
    // this compiles
    //myMap: {
    //    "1": string;
    //    "2": string;
    //    "3": string;
    //    "4": string;
    //};
}

var testObject:ITestInterface = {
    myMap: {
        "1": "a",
        "2": "b",
        "3": "c",
        "4": "d"
    }
};

var testObject2 = {
    myMap: {
        "1": "a",
        "2": "b",
        "3": "c",
        "4": "d"
    }
};

function testFunction(testInterface:ITestInterface) {   
}

// this works:
testFunction(testObject);

// this causes a compile error, why?
testFunction(testObject2);

Supplied parameters do not match any signature of call target:
Types of property 'myMap' of types '{ myMap: { "1": string; "2": string; "3": string; "4": string; }; }' and 'ITestInterface' are incompatible:
Index signatures of types '{ "1": string; "2": string; "3": string; "4": string; }' and // '{ [id: string]: string; }' are incompatible.
Could not select overload for 'call' expression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions