Hey I’m coming from Typescript and Im trying to fi...
# announcements
b
Hey I’m coming from Typescript and Im trying to figure out how to “translate” some typings into Kotlin. I currently have this in Typescript code snippet where I am defining an interface general (
Version
) 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]
)
Copy code
// 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?