Bug Report
⏯ Playground Link
Playground link with relevant code
💻 Code
abstract class MyAbstractGeneric<TValue1, TValue2 extends string, TValue3> {}
class MyConcreteGeneric<TValue1, TValue3> extends MyAbstractGeneric<TValue1, 'test', TValue3> {}
function myGenericFunction<TValue1, TValue2 extends string, TValue3>(abstractVar: MyAbstractGeneric<TValue1, TValue2, TValue3>) {}
let myConcreteVar = new MyConcreteGeneric<string, number>();
// Inferred as <unknown, string, unknown>
myGenericFunction(myConcreteVar);
let myAbstractVar = new MyConcreteGeneric<string, number>() as MyAbstractGeneric<string, any, number>;
// Inferred as <string, any, number>
myGenericFunction(myAbstractVar);
If I declare a member of a generic type inside the abstract class everything works (for the declared members)
abstract class MyAbstractGeneric<TValue1, TValue2 extends string, TValue3> {
myVar?:TValue1;
}
class MyConcreteGeneric<TValue1, TValue3> extends MyAbstractGeneric<TValue1, 'test', TValue3> {}
function myGenericFunction<TValue1, TValue2 extends string, TValue3>(abstractVar: MyAbstractGeneric<TValue1, TValue2, TValue3>) {}
let myConcreteVar = new MyConcreteGeneric<string, number>();
// Inferred as <string, string, unknown>
myGenericFunction(myConcreteVar);
let myAbstractVar = new MyConcreteGeneric<string, number>() as MyAbstractGeneric<string, any, number>;
// Inferred as <string, any, number>
myGenericFunction(myAbstractVar);
But then some complex type using any of the generic types is not considered apparently
import { Get } from 'type-fest';
abstract class MyAbstractGeneric<TValue1, TValue2 extends string, TValue3> {
myVar?:Get<TValue1, TValue2>;
}
class MyConcreteGeneric<TValue1, TValue3> extends MyAbstractGeneric<TValue1, 'test', TValue3> {}
function myGenericFunction<TValue1, TValue2 extends string, TValue3>(abstractVar: MyAbstractGeneric<TValue1, TValue2, TValue3>) {}
let myConcreteVar = new MyConcreteGeneric<string, number>();
// Inferred as <unknown, string, unknown>
myGenericFunction(myConcreteVar);
let myAbstractVar = new MyConcreteGeneric<string, number>() as MyAbstractGeneric<string, any, number>;
// Inferred as <string, any, number>
myGenericFunction(myAbstractVar);
🙁 Actual behavior
The function called on a child of a generic abstract has the wrong type inferred if no concrete members of the type(s) are declared in the abstract class.
🙂 Expected behavior
The generic types should be inferred regardless of their use inside the class
Bug Report
⏯ Playground Link
Playground link with relevant code
💻 Code
If I declare a member of a generic type inside the abstract class everything works (for the declared members)
But then some complex type using any of the generic types is not considered apparently
🙁 Actual behavior
The function called on a child of a generic abstract has the wrong type inferred if no concrete members of the type(s) are declared in the abstract class.
🙂 Expected behavior
The generic types should be inferred regardless of their use inside the class