backend-plugin-api: add ServiceFactoryOrFunction type
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -347,6 +347,11 @@ export interface ServiceFactoryConfig<
|
||||
service: ServiceRef<TService, TScope>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type ServiceFactoryOrFunction<TService = unknown> =
|
||||
| ServiceFactory<TService>
|
||||
| (() => ServiceFactory<TService>);
|
||||
|
||||
// @public
|
||||
export type ServiceRef<
|
||||
TService,
|
||||
@@ -364,7 +369,7 @@ export interface ServiceRefConfig<TService, TScope extends 'root' | 'plugin'> {
|
||||
// (undocumented)
|
||||
defaultFactory?: (
|
||||
service: ServiceRef<TService, TScope>,
|
||||
) => Promise<ServiceFactory<TService> | (() => ServiceFactory<TService>)>;
|
||||
) => Promise<ServiceFactoryOrFunction<TService>>;
|
||||
// (undocumented)
|
||||
id: string;
|
||||
// (undocumented)
|
||||
|
||||
@@ -20,5 +20,6 @@ export type {
|
||||
TypesToServiceRef,
|
||||
ServiceFactory,
|
||||
ServiceFactoryConfig,
|
||||
ServiceFactoryOrFunction,
|
||||
} from './types';
|
||||
export { createServiceRef, createServiceFactory } from './types';
|
||||
|
||||
@@ -71,13 +71,22 @@ export type ServiceFactory<TService = unknown> =
|
||||
>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents either a {@link ServiceFactory} or a function that returns one.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type ServiceFactoryOrFunction<TService = unknown> =
|
||||
| ServiceFactory<TService>
|
||||
| (() => ServiceFactory<TService>);
|
||||
|
||||
/** @public */
|
||||
export interface ServiceRefConfig<TService, TScope extends 'root' | 'plugin'> {
|
||||
id: string;
|
||||
scope?: TScope;
|
||||
defaultFactory?: (
|
||||
service: ServiceRef<TService, TScope>,
|
||||
) => Promise<ServiceFactory<TService> | (() => ServiceFactory<TService>)>;
|
||||
) => Promise<ServiceFactoryOrFunction<TService>>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user