I have a repo with a lot of complex types for the project I'm working on. Interfaces that extend other interfaces, mapped types, generic types etc etc etc.
For example let's say I have
interface Base {
foo: string;
bar: string;
}
interface Something<T extends string> extends Base {
baz: T;
}
interface A extends Something<'hello'> {
qux: string;
}
interface B extends Something<'world'> {
abc: number
}
interface C extends Something<'goodbye'> {
def: boolean;
}
interface Woop<T extends 'a' | 'b' | 'c'> {
a: A;
b: B;
c: C;
}[T];
...and so on, just to get an idea.
Now, for documentation purposes, I need to send some of these types to a co-worker who doesn't work with TypeScript, so that he can easily see what properties the interface C
has. It doesn't seem very useful to send him a large complex TypeScript file with lots of extended interfaces, generics, mapped types etc, so I'm looking for a way (tool?) to break down a set of types into primitives, so that I can send him this instead:
interface Woop = {
foo: string;
bar: string;
baz: 'hello'
qux: string;
} | {
foo: string;
bar: string;
baz: 'world'
abc: number;
} | {
foo: string;
bar: string;
baz: 'goodbye'
def: boolean;
}
Is there such a tool? It feels similar to what IDEs do when inspecting types during development, it usually simplifies/flattens complex types into their combined properties etc.