Lets have following types example where I want to be able to define my custom object where key is flag name and value is flags body.
interface FlagModel {
value: boolean;
}
interface GenericFlagsModel<T extends Record<string, FlagModel>> {
flags: T
}
enum FLAG_NAMES {
FLAG_FOO = 'flag-foo',
FLAG_BAR = 'flag-bar'
}
type CustomFlagsModel = GenericFlagsModel<{
[FLAG_NAMES.FLAG_FOO]: FlagModel,
[FLAG_NAMES.FLAG_BAR]: FlagModel
}>
Looking at CustomFlagsModel
you can see that I need to explicitly define FlagModel
as a value. Is it possible to avoid this? For example like:
type CustomFlagsModel = GenericFlagsModel<{
[FLAG_NAMES.FLAG_FOO],
[FLAG_NAMES.FLAG_BAR]
}>
以下是否符合您的需求?
type CustomFlagsModel = GenericFlagsModel<Record<FLAG_NAMES, FlagModel>>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.