Here is a function I am working with:
type DefaultEntity = {
id: string;
createdBy: string;
[fieldName: string]: unknown;
};
abstract find<T, Schema extends string | (new () => T)>(
schema: Schema,
id: string,
): Promise<(Schema extends string ? DefaultEntity : T) | null>;
Issue: The return type when calling the function with a string as the schema
is DefaultEntity
. However, when using MyClass
as the schema argument, the return type is unknown
instead of MyClass
. This is unexpected because T
is supposed to become MyClass
. Is this a mistake on my end or is it something that TypeScript cannot handle?