S
S
sanex33392015-08-13 15:51:08
typescript
sanex3339, 2015-08-13 15:51:08

Is it possible to specify one single type for all elements of an object?

Let's say there is an object
obj = {};
it will contain Ne number of elements.
Is it possible to somehow specify for this object that all element values ​​in it will be of the same type,
for example Object or string, without specifying each element of the type:

obj = {
    abc: <string>'abc',
    def: <string>'def'
    ....
}

Is there any way, through the interface, there, or something else?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sanex3339, 2015-08-13
@sanex3339

Found the answer

obj: {[id: string]: string} = { 
    abc: 'abc',
    def: 'def'
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question