0

I created a Dictionary<TValue> on TypeScript, but it doesn't works like I want, unless that I use it like an array instead of object. It's my Dictionary class:

class Dictionary<TValue> {
    [index: string]: TValue;
}

So I can only use it like this:

var instanceOfDictionary: Dictionary<string> = ...;
console.log(instanceOfDictionary["test"]);

But I would like use like:

console.log(instanceOfDictionary.test);

Is it possible?

1 Answer 1

2

Is it possible?

Not unless you explicitly add test as a member. So, no.

Sign up to request clarification or add additional context in comments.

1 Comment

Really, I think that if I turn it in a class that allow this member will better for me, are limited number of member (about 10), so I think that it'll be better than I use "undefined" members. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.