I have something like the following:
const items: {
get: (name: string) => '-' + name,
log: () => { console.log('Hello') },
commands: {
table: ( name: string ) => 'table-' + name;
// lots more functions / objects.
}
// lots more functions / objects.
}
Is there a way to created a type or interface with all the function names flattened / on one level like this:
interface Items {
get: ( name: string ) => string;
log: () => void;
table: ( name: string ) => string;
}
I've got as far as writing:
type Mapped<T extends Record<string, any>> = {
[K in keyof T]: T[K] extends Record<string, unknown> ? Mapped<T[K]> : T[K];
};
type Items = Mapped<typeof items>;
But I'm not flattening them into one level. I'm not 100% sure about doing recursively doing this and getting the results on one level.