Why do I get errors in e4, e5, e6? All of them match SomeClass type so they have to match generic RES.
class SomeClass {
a: string;
b: number;
c: boolean;
}
class ChildOfSomeClass extends SomeClass {}
const someFunc1 = <RES extends SomeClass>() => {
const e1: SomeClass = { a: "aaa", b: 123, c: true }; // ok
const e2: SomeClass = new SomeClass(); // ok
const e3: SomeClass = new ChildOfSomeClass(); // ok
// Type '{ a: string; b: number; c: true; }' is not assignable to type 'RES'.ts(2322)
const e4: RES = { a: "aaa", b: 123, c: true };
// Type 'SomeClass' is not assignable to type 'RES'.ts(2322)
const e5: RES = new SomeClass();
// Type 'ChildOfSomeClass' is not assignable to type 'RES'.ts(2322)
const e6: RES = new ChildOfSomeClass();
};
I eventually want someFunc1 to return RES | Promise<RES> but for the sake of the example, I simplified it.