i have an enum:
JavaScript
x
4
1
enum INFO_CODES {
2
goToInit = 'goToInit',
3
lockIp = 'lockIp',
4
}
and i want to create an object(or enum also) with the same properties (only goToInit and lockIp)
JavaScript
1
6
1
const SOME_OBJ = {
2
goToInit: function, //here i need function
3
lockIp: function,//here i need function
4
someProp:function //here i need mistake,can create only like in
5
INFO_CODES props.
6
}
Advertisement
Answer
You can use a Record
and just use the enum
as the first generic parameter for the key and then whatever function type you want to have next.
JavaScript
1
12
12
1
enum INFO_CODES {
2
goToInit = 'goToInit',
3
lockIp = 'lockIp',
4
}
5
6
type result = Record<INFO_CODES, () => void>;
7
8
const test: result = {
9
goToInit: () => console.log("test"),
10
lockIp: () => console.log("lockIp"),
11
}
12