TypeScript Version: 2.3.4, I would however expect 2.4.0 version to be failing too, as nothing is in the changelog about this
Code
class Person {
constructor(public name: string) { }
}
class Base<T> {
reference?: T
name: string
constructor(name: string) {
// Assign properties from T to this
this.name = name
}
static fromObject<T extends { name: string }>(object: T) {
const base = new Base<T>(object.name)
base.reference = object
return base
}
}
class Master<T> extends Base<T> {
static fromBase<T>(base: Base<T>) {
const master = new Master<T>(base.name)
master.reference = base.reference
return master
}
static fromObject<T extends { name: string }>(object: T) {
return Master.fromBase(Base.fromObject(object))
}
}
class PersonMaster extends Master<Person> {
constructor(person: Person) {
super(person.name)
this.reference = person
}
static fromBase(base: Base<Person>) {
return new PersonMaster(base)
}
}
Expected behavior:
Expecting PersonMaster.fromBase to accept PersonMaster as return value.
Actual behavior:
Error: (it will actually compile just fine, it will only flag class as error, or if corrected, will make bad assumptions about type)
Class static side typeof PersonMaster incorrectly extends base class static side typeof Master. Types of property fromBase are incompatible. Type (base: Base<Person>) => PersonMaster is not assignable to type <T>(base: Base<T>) => Master<{}>. Types of parameters base and base are incompatible. Type Base<T> is not assignable to Base<Person>. Type T is not assignable to type Person.
Reactions are currently unavailable
TypeScript Version: 2.3.4, I would however expect 2.4.0 version to be failing too, as nothing is in the changelog about this
Code
Expected behavior:
Expecting PersonMaster.fromBase to accept PersonMaster as return value.
Actual behavior:
Error: (it will actually compile just fine, it will only flag class as error, or if corrected, will make bad assumptions about type)
Class static side typeof PersonMaster incorrectly extends base class static side typeof Master. Types of property fromBase are incompatible. Type (base: Base<Person>) => PersonMaster is not assignable to type <T>(base: Base<T>) => Master<{}>. Types of parameters base and base are incompatible. Type Base<T> is not assignable to Base<Person>. Type T is not assignable to type Person.