Skip to content

Index constraint does not constrain #3150

@dsherret

Description

@dsherret

It seems the index constraint doesn't seem to constrain anymore... if it does, then I blame it being early in the morning.

Copying the code from Ryan's post here:

class Customer {
    dummyProperty: string;
}

var map: { [email: string]: Customer; } = { };
map['foo@gmail.com'] = new Customer(); // OK
map[14] = new Customer(); // Not OK, 14 is not a string -- ACTUALLY, this compiles now
map['bar@hotmail.com'] = 'x'; // Not OK, x is not a customer

Playground

Apologies if this has already been raised, but I couldn't find a duplicate issue. Maybe this is now by design?

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions