Previously, in typescript 4.4.4, this code compiled successfully:
/**
* type to get only those properties that are functions
*/
type FunctionProperties<T> = {
[P in keyof T]: T[P] extends (...args: any) => any ? P : never;
}[keyof T];
type ReturnTypeOfMethod<T, K extends FunctionProperties<T>> = ReturnType<T[K]>;
However, the same code now fails to compile in typescript 4.5.4 - see Playground 4.5.4 example
Type 'T[K]' does not satisfy the constraint '(...args: any) => any'.
Type 'T[FunctionProperties<T>]' is not assignable to type '(...args: any) => any'.
Type 'T[T[keyof T] extends (...args: any) => any ? keyof T : never]' is not assignable to type '(...args: any) => any'.
Type 'T[keyof T]' is not assignable to type '(...args: any) => any'.
Type 'T[string] | T[number] | T[symbol]' is not assignable to type '(...args: any) => any'.
Type 'T[string]' is not assignable to type '(...args: any) => any'.
It is interesting to note that the ReturnTypeNumber
type still reflects the correct type (number
in this case).
Do you have any thoughts on why this code no longer works or suggestions on how to resolve it without using @ts-ignore
as a solution?