'Can I short-circuit type evaluation?
I'm trying to create a composable configuration framework wherein each node in the dependency graph can access all of its upstream nodes. Although I've managed to express this by explicitly declaring each node's dependencies, I'm trying to find a way to simply pass the entire configuration object into the framework and have it extract and inject the required dependencies.
Perhaps unsurprisingly, this results in a circular reference, e.g.:
type Store = typeof store;
const store = {
foo: 'foo',
};
type Module = typeof module;
export const module = {
store,
accessors: (module: Pick<Module, 'store'>) => ({
getFoo: () => module.store.foo,
}),
};
As I mentioned, this works fine if accessors
is typed as (module: { store: Store }) => {...}
but the purpose of this work is to provide an abstraction over the dependency graph so that each node can define its type and the framework determines which properties from the module config should be injected.
Is there a way to short-circuit the evaluation of Pick<Module, 'store'>
so that the compiler doesn't attempt to infer the type of accessors
, and thus avoid the circular reference?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|