From de42fa4ef492fefab5223627cd88e87473431f50 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 13 Jan 2023 15:41:38 +0100 Subject: [PATCH] backend-plugin-api: fix unexpected required options for root factories Co-authored-by: blam Co-authored-by: Johan Haals Signed-off-by: Patrik Oldsberg --- .../src/services/system/types.test.ts | 15 +++++++++++++-- .../src/services/system/types.ts | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/backend-plugin-api/src/services/system/types.test.ts b/packages/backend-plugin-api/src/services/system/types.test.ts index 43272a52bf..fab0232380 100644 --- a/packages/backend-plugin-api/src/services/system/types.test.ts +++ b/packages/backend-plugin-api/src/services/system/types.test.ts @@ -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'; }, }); diff --git a/packages/backend-plugin-api/src/services/system/types.ts b/packages/backend-plugin-api/src/services/system/types.ts index 5da6dc990a..a482d10dfb 100644 --- a/packages/backend-plugin-api/src/services/system/types.ts +++ b/packages/backend-plugin-api/src/services/system/types.ts @@ -176,7 +176,7 @@ export function createServiceFactory< TOpts extends object | undefined = undefined, >( config: RootServiceFactoryConfig, -): (params: TOpts) => ServiceFactory; +): () => ServiceFactory; /** * Creates a root scoped service factory with optional options. *