Merge pull request #2689 from NoelDeMartin/MOBILE-3320

MOBILE-3320 types: Exclude any singleton props
main
Dani Palou 2021-03-03 14:14:14 +01:00 committed by GitHub
commit e026f42ee8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -64,10 +64,17 @@ const OBJECT_PROTOTYPE = Object.getPrototypeOf(Object);
let singletonsInjector: Injector | null = null;
/**
* Helper to get service class methods.
* Helper to get service class properties that are methods.
*/
type GetMethods<T> = {
[K in keyof T]: T[K] extends (...args: unknown[]) => unknown ? K : never;
[K in keyof T]: T[K] extends (...args: unknown[]) => unknown ? K : never
}[keyof T];
/**
* Helper to get service class properties that are not methods.
*/
type GetNonMethods<T> = {
[K in keyof T]: T[K] extends (...args: unknown[]) => unknown ? never : K
}[keyof T];
/**
@ -76,7 +83,7 @@ type GetMethods<T> = {
* @see makeSingleton
*/
export type CoreSingletonProxy<Service, Getters extends keyof Service = never> =
Pick<Service, GetMethods<Service>> &
Pick<Service, Exclude<GetMethods<Service>, GetNonMethods<Service>>> &
Pick<Service, Getters> &
{
instance: Service;