From e956b987f26744de34d23959651a8a92fc44a7da Mon Sep 17 00:00:00 2001 From: James Daniels Date: Mon, 7 Feb 2022 14:47:49 -0500 Subject: [PATCH 1/3] Fix for Typescript 4.5 inference breaks in the PromiseProxy --- src/compat/proxy.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/compat/proxy.ts b/src/compat/proxy.ts index 127ceadcd..ef1565018 100644 --- a/src/compat/proxy.ts +++ b/src/compat/proxy.ts @@ -1,20 +1,22 @@ 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 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: Parameters>) => Promise> } & + { [K in PromiseReturningFunctionPropertyNames]: + (...args: Parameters>) => ReturnTypeOrNever }; // DEBUG quick debugger function for inline logging that typescript doesn't complain about From dba2f802a47358b6b5acf09a093a85a89665dcb7 Mon Sep 17 00:00:00 2001 From: James Daniels Date: Mon, 7 Feb 2022 15:22:42 -0500 Subject: [PATCH 2/3] Whoops threw away params, add ParmetersOrNever --- src/compat/proxy.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compat/proxy.ts b/src/compat/proxy.ts index ef1565018..882236f17 100644 --- a/src/compat/proxy.ts +++ b/src/compat/proxy.ts @@ -1,9 +1,11 @@ import { NgZone } from '@angular/core'; import { Observable } from 'rxjs'; +import firebase from 'firebase/compat'; 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]: ReturnTypeOrNever extends Promise ? K : never }[FunctionPropertyNames]; @@ -13,11 +15,8 @@ type NonPromiseReturningFunctionPropertyNames = { 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>) => ReturnTypeOrNever }; - + { [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 From f370d2e52abc4773c1c80969b29087423e684ad9 Mon Sep 17 00:00:00 2001 From: James Daniels Date: Mon, 7 Feb 2022 15:56:22 -0500 Subject: [PATCH 3/3] Whoops left in this testing import --- src/compat/proxy.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/compat/proxy.ts b/src/compat/proxy.ts index 882236f17..2ea9169bf 100644 --- a/src/compat/proxy.ts +++ b/src/compat/proxy.ts @@ -1,6 +1,5 @@ import { NgZone } from '@angular/core'; import { Observable } from 'rxjs'; -import firebase from 'firebase/compat'; type MyFunction = (...args: any[]) => any; type FunctionPropertyNames = { [K in keyof T]: T[K] extends MyFunction ? K : never }[keyof T];