I have an object that can have an n
number of properties, each one the same but with their n
value in the name.
Example:
const obj = {
'data-element-0': 'something',
'data-element-1': 'something else',
'data-element-2': 'something as well',
'data-element-3': 'something to feel included',
};
Is there any way to define this interface with more specificity than just using
interface Obj {
[key: string]: string;
}
You can do smth like that:
UPDATE I have also make helpers fot double numbers, from: 0-99:
UPDATE
Here you have an util for generating number range from 0 to 99999
Demo
UPDATE 3
If you still want to generate literal numbers, not string numbers, you can use this code, which has been shamelessly stolen from here
*UPDATE 8 September 2021
Since TS 4.5, see Tail recursion PR, it is possible to generate much longer number range.
See example:
Related question
Playground