I am looking to retrieve a specific type from the fn
function. Let's take a look at the code snippet below:
for more information, this is a continuation of a previous question on Stack Overflow: this question
class Person {
firstName: string;
lastName: string;
}
class Book {
title: string;
author: Person;
}
type MakePropTypesAny<T> = T extends object
? {
[K in keyof T]: MakePropTypesAny<Partial<T[K]>>;
}
: any;
type ClassConstructor<T> = new (...args: any[]) => T;
type ParseReturnType<T> = T; // < - - - - - - - - - - - - - - - - - - what here?
const fn = <T>(
obj: ClassConstructor<T>,
fields: Partial<MakePropTypesAny<T>>
): ParseReturnType<T> => {
return {} as any;
};
const res = fn(Book, { author: { firstName: true } });
res
currently has the type of Book
, but I want it to have the following type instead:
type ToBeReturned = {
author: {
firstName: string; // because Person.firstName is 'string'
};
};
The above type represents the fields passed in the fields
argument, with field types taken from the Book
class