1

I am not familiar with typescript. Could someone please explain what data type of typescript field selectedNames below is.

class Doit { private selectedNames : { [level: number] : {[name: string]: boolean} } = {}; }

Thank you.

2 Answers 2

1

selectedNames has an object type. It has a numeric index signature, whose type for convenience let's call it T. In other words, selectedNames has properties with numeric property names and T property types.

And T is also an object type. T has a string index signature, whose type is boolean. In other words, T has properties with string property names and boolean property types.

And the = {} is an initializer that assigns an empty object to the selectedNames property of class Doit.

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

1 Comment

Thank you for your help.
0

[level: number] : {[name: string]: boolean} is the type. It describes the dictionary pattern

[level : number] is the key. {[name: string]: boolean} are the values, in this case another dictionary string to bool.

compare http://www.typescriptlang.org/Handbook#interfaces-array-types

Comments

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.