Ben Toofer
09/28/2020, 3:04 PMVersion
) which can be extended to defined a specific object structure. I then have a defined type VersionDefinition<V extends Version>
which has a simple data structure to it but it is restricted to implement the keys of the specified version ([x in keyof V]
)
// Defining a map interface of a key type string and value type of any
interface Version {
[key: String]: any
}
// Defining an object type that enforces the implementation of the specified version (V)
type VersionDefinition<V extends Version> = {
[x in keyof V]: {
description: String,
headerName: FakeHeader,
}
}
// Version 1 interface
interface Version1 extends Version {
foo: Integer,
bar: Integer,
...
}
// Version 1 implementation
const VERSION_1_DEFINITION: VersionDefinition<Version1> = {
foo: {
description: "Bar description",
headerName: FakeHeader.FOO
},
bar: {
description: "Bar description",
headerName: FakeHeader.BAR
}
...
}
I know I can create the Version1
interface as a data class in Kotlin but my question then is there a way to create something similar to the VersionDefinition<V extends Version>
where it enforces you to implement the keys of some interface, data class or map?mserralta
09/28/2020, 3:11 PM