backend-plugin-api: properly forward lack of feature options
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -56,6 +56,18 @@ describe('createBackendPlugin', () => {
|
||||
// @ts-expect-error
|
||||
expect(plugin({ b: 'b' })).toBeDefined();
|
||||
});
|
||||
|
||||
it('should create plugins without options', () => {
|
||||
const plugin = createBackendPlugin({
|
||||
id: 'x',
|
||||
register() {},
|
||||
});
|
||||
expect(plugin).toBeDefined();
|
||||
// @ts-expect-error
|
||||
expect(plugin({ a: 'a' })).toBeDefined();
|
||||
// @ts-expect-error
|
||||
expect(plugin({})).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('createBackendModule', () => {
|
||||
@@ -86,4 +98,17 @@ describe('createBackendModule', () => {
|
||||
// @ts-expect-error
|
||||
expect(mod({ b: 'b' })).toBeDefined();
|
||||
});
|
||||
|
||||
it('should create modules without options', () => {
|
||||
const mod = createBackendModule({
|
||||
pluginId: 'x',
|
||||
moduleId: 'y',
|
||||
register() {},
|
||||
});
|
||||
expect(mod).toBeDefined();
|
||||
// @ts-expect-error
|
||||
expect(mod({ a: 'a' })).toBeDefined();
|
||||
// @ts-expect-error
|
||||
expect(mod({})).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -43,7 +43,9 @@ export interface BackendPluginConfig<TOptions> {
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export function createBackendPlugin<TOptions>(
|
||||
export function createBackendPlugin<
|
||||
TOptions extends { [name: string]: unknown } | undefined = undefined,
|
||||
>(
|
||||
config: BackendPluginConfig<TOptions>,
|
||||
): undefined extends TOptions
|
||||
? (options?: TOptions) => BackendFeature
|
||||
@@ -67,7 +69,9 @@ export interface BackendModuleConfig<TOptions> {
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export function createBackendModule<TOptions>(
|
||||
export function createBackendModule<
|
||||
TOptions extends { [name: string]: unknown } | undefined = undefined,
|
||||
>(
|
||||
config: BackendModuleConfig<TOptions>,
|
||||
): undefined extends TOptions
|
||||
? (options?: TOptions) => BackendFeature
|
||||
|
||||
Reference in New Issue
Block a user