From f61bc7d563abb04e8c8f296997ec0500bf5bb2ea Mon Sep 17 00:00:00 2001 From: James Daniels Date: Mon, 7 Feb 2022 16:09:59 -0500 Subject: [PATCH] fix(compat): Typescript 4.5 inference breaks the PromiseProxy (#3144) Fixes #3090 #3088 --- src/compat/proxy.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compat/proxy.ts b/src/compat/proxy.ts index 127ceadcd..2ea9169bf 100644 --- a/src/compat/proxy.ts +++ b/src/compat/proxy.ts @@ -1,21 +1,21 @@ import { NgZone } from '@angular/core'; import { Observable } from 'rxjs'; -// tslint:disable:ban-types -type FunctionPropertyNames = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T]; +type MyFunction = (...args: any[]) => any; +type FunctionPropertyNames = { [K in keyof T]: T[K] extends MyFunction ? K : never }[keyof T]; +type ReturnTypeOrNever = T extends MyFunction ? ReturnType : never; +type ParametersOrNever = T extends MyFunction ? Parameters : never; type PromiseReturningFunctionPropertyNames = { - [K in FunctionPropertyNames]: ReturnType extends Promise ? K : never + [K in FunctionPropertyNames]: ReturnTypeOrNever extends Promise ? K : never }[FunctionPropertyNames]; type NonPromiseReturningFunctionPropertyNames = { - [K in FunctionPropertyNames]: ReturnType extends Promise ? never : K + [K in FunctionPropertyNames]: ReturnTypeOrNever extends Promise ? never : K }[FunctionPropertyNames]; -type NonFunctionPropertyNames = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T]; -// tslint:enable:ban-types +type NonFunctionPropertyNames = { [K in keyof T]: T[K] extends MyFunction ? never : K }[keyof T]; export type ɵPromiseProxy = { [K in NonFunctionPropertyNames]: Promise } & - { [K in NonPromiseReturningFunctionPropertyNames]: (...args: Parameters) => Promise> } & - { [K in PromiseReturningFunctionPropertyNames]: (...args: Parameters) => ReturnType }; - + { [K in NonPromiseReturningFunctionPropertyNames]: (...args: ParametersOrNever) => Promise> } & + { [K in PromiseReturningFunctionPropertyNames]: T[K] }; // DEBUG quick debugger function for inline logging that typescript doesn't complain about // wrote it for debugging the ɵlazySDKProxy, commenting out for now; should consider exposing a