import { assignProps } from 'true-di/utils';
const { assignProps } = require('true-di/utils');
function assignProps<IContainer, Name extends keyof IContainer>(
mapping: IMapping<IContainer, IContainer[Name]>,
): (item: IContainer[Name], container: IContainer) => void
type KeysOfType<T, F> = {
[P in keyof T]: IfEquals<{ [Q in P]: T[P] }, { [Q in P]: F }, P>
}[keyof T];
export type IMapping<IContainer extends object, T> = {
[p in keyof T]?: KeysOfType<IContainer, T[p]>
}
import diContainer from 'true-di';
import { assignProps } from 'true-di/utils';
type Node = {
child: Node;
parent: Node;
name: string;
}
type Container = {
parentItem: Node;
childItem: Node;
}
const createNodeFactory = (name: string): Node => () => ({
child: null, parent: null, name
});
const container = diContainer<Container>({
parentItem: [
createNodeFactory('Parent'),
assignProps({ child: 'childItem' }),
],
childItem: [
createNodeFactory('Child'),
assignProps({ parent: 'parentItem' }),
],
});