Skip to content

Commit

Permalink
fix(compat): Typescript 4.5 inference breaks the PromiseProxy (#3144)
Browse files Browse the repository at this point in the history
Fixes #3090 #3088
  • Loading branch information
jamesdaniels authored Feb 7, 2022
1 parent 8b693e4 commit f61bc7d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/compat/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { NgZone } from '@angular/core';
import { Observable } from 'rxjs';

// tslint:disable:ban-types
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
type MyFunction = (...args: any[]) => any;
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends MyFunction ? K : never }[keyof T];
type ReturnTypeOrNever<T> = T extends MyFunction ? ReturnType<T> : never;
type ParametersOrNever<T> = T extends MyFunction ? Parameters<T> : never;
type PromiseReturningFunctionPropertyNames<T> = {
[K in FunctionPropertyNames<T>]: ReturnType<T[K]> extends Promise<any> ? K : never
[K in FunctionPropertyNames<T>]: ReturnTypeOrNever<T[K]> extends Promise<any> ? K : never
}[FunctionPropertyNames<T>];
type NonPromiseReturningFunctionPropertyNames<T> = {
[K in FunctionPropertyNames<T>]: ReturnType<T[K]> extends Promise<any> ? never : K
[K in FunctionPropertyNames<T>]: ReturnTypeOrNever<T[K]> extends Promise<any> ? never : K
}[FunctionPropertyNames<T>];
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
// tslint:enable:ban-types
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends MyFunction ? never : K }[keyof T];

export type ɵPromiseProxy<T> = { [K in NonFunctionPropertyNames<T>]: Promise<T[K]> } &
{ [K in NonPromiseReturningFunctionPropertyNames<T>]: (...args: Parameters<T[K]>) => Promise<ReturnType<T[K]>> } &
{ [K in PromiseReturningFunctionPropertyNames<T>]: (...args: Parameters<T[K]>) => ReturnType<T[K]> };

{ [K in NonPromiseReturningFunctionPropertyNames<T>]: (...args: ParametersOrNever<T[K]>) => Promise<ReturnTypeOrNever<T[K]>> } &
{ [K in PromiseReturningFunctionPropertyNames<T>]: 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
Expand Down

0 comments on commit f61bc7d

Please sign in to comment.