I am working with a series of classes that have a body
property defined within them. Here is an example:
class Foo {
body: {foo: string}
constructor(body: Record<string, string>) {
this.body = { foo: body.foo }
}
}
class Bar {
body: {bar: string}
constructor(body: Record<string, string>) {
this.body = { bar: body.bar }
}
}
These classes are then assigned to an object where they can be accessed by a string:
const pages = {
'foo': Foo,
'bar': Bar
} as const
I also have a union type that includes all the classes:
type Pages = typeof pages[keyof typeof pages]
// typeof Foo | typeof Bar
My goal is to create an object that references the types of the body
properties from each class in the pages
object. For example:
// The values for `fooBody` and `barBody` should be types here
{
'fooBody': {foo: string},
'barBody': {bar: string}
}