backend-plugin-api: fix unexpected required options for root factories

Co-authored-by: blam <ben@blam.sh>
Co-authored-by: Johan Haals <johan.haals@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-13 15:41:38 +01:00
parent b3a75d7664
commit de42fa4ef4
2 changed files with 14 additions and 3 deletions
@@ -167,6 +167,14 @@ describe('createServiceFactory', () => {
},
});
expect(metaFactory).toEqual(expect.any(Function));
// @ts-expect-error
metaFactory({});
// @ts-expect-error
metaFactory(null);
// @ts-expect-error
metaFactory(undefined);
metaFactory();
});
it('should create root scoped factory with dependencies and optional options', () => {
@@ -213,14 +221,17 @@ describe('createServiceFactory', () => {
unused(root1, root2);
return { root };
},
async factory({ plugin }, { root }) {
async factory({ plugin, root: rootB }, { root }) {
const root1: number = root;
// @ts-expect-error
const root2: string = root;
const root3: number = rootB;
// @ts-expect-error
const root4: string = rootB;
const plugin3: boolean = plugin;
// @ts-expect-error
const plugin4: number = plugin;
unused(root1, root2, plugin3, plugin4);
unused(root1, root2, root3, root4, plugin3, plugin4);
return 'x';
},
});
@@ -176,7 +176,7 @@ export function createServiceFactory<
TOpts extends object | undefined = undefined,
>(
config: RootServiceFactoryConfig<TService, TImpl, TDeps>,
): (params: TOpts) => ServiceFactory<TService>;
): () => ServiceFactory<TService>;
/**
* Creates a root scoped service factory with optional options.
*