"Cannot convert 'T' to 'string'"

Topics: General
Jun 3, 2013 at 8:10 PM
Edited Jun 3, 2013 at 8:12 PM
It seems like this code should compile (under 0.9 beta):
class LazyArray<T> {
    private objects = <{ [objectId: string]: T; }>{};

    array() {
        return this.objects;
    }
}

var lazyArray = new LazyArray<string>();
var value: string = lazyArray.array()["test"];
But tsc returns "Cannot convert 'T' to 'string'".

Is that right?
Developer
Jun 4, 2013 at 2:46 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Developer
Jun 4, 2013 at 2:48 AM
Something is funky here. I've created a work item for you (https://typescript.codeplex.com/workitem/1103). If you remove the type annotation on value then it's typed as T, but it shouldn't be showing unspecialized generic parameters at that point.
Jun 4, 2013 at 4:50 PM
Exactly. Instead of value being typed as T, it should be typed as string, right?
Developer
Jun 4, 2013 at 8:04 PM
Yeah, you've got it, this should be working as you expect.