Hello guys, I am working on a project which is a monorepo, it has:
- apps
- webapp
- packages
- lib1
- lib2
- types (shared among all projects in monorepo)
- main
The thing here is types has a generic type, let's call it Generic<A> with this structure:
type Generic<A> = {
field: string,
inner: A
}
So each library (lib1, lib2, etc...) is using Generic with it's own specific type, let's say:
export type InnerLib1 = {
fieldOfLib1: string,
}
const internalMethodFromLib = ():Generic<InnerLib1> => ...
export default {
internalMethodFromLib
} satisfies ...
And the main library, which kind of consolidates as an entry point for all lib x, has a method that returns the Generic<?> according to some pattern matching, for example:
const someMethod = (param: 'n1' | 'n2') => match(param)
.with('n1', () => lib1)
.with('n2', () => lib2)
.run()
Everything works well and in webapp project I am calling to someMethod passing param to get an object which returns all methods exported from lib1 or lib2, etc.
// This returns the Generic<InnerLib1>
const lib = someMethod('n1')
lib.internalMethodFromLib()
// This would return Generic<InnerLib2>
const lib = someMethod('n2')
lib.internalMethodFromLib()
My problem now is what type assign to the call lib.internalMethodFromLib() because it can be Generic<InnerLib1> or Generic<InnerLib2> or any other inner type that is not available in webapp project, I know there is no way to do something like Generic<_> and I am not sure what options I have here