Microsoft/TypeScript
在 GitHub 查看Intersection type of abstract classes does not throw error if same member exists in multiple abstract classes
Open
#26,617 创建于 2018年8月22日
BugDomain: IntersectionHelp Wanted
描述
TypeScript Version: 3.0.1
Search Terms: "Intersection", "abstract"
Code
export type Constructor<T = {}> = new (...args: any[]) => T;
abstract class Outer1 {
abstract same: number;
abstract notSame: string;
}
abstract class Outer2 {
abstract same: number;
}
function Mixin1<TBase extends Constructor>(Base: TBase) {
abstract class Inner1 extends Base { // Same as Outer1
abstract same: number;
}
return Inner1;
}
function Mixin2<TBase extends Constructor>(Base: TBase) {
abstract class Inner2 extends Base { // Same as Outer2
abstract same: number;
}
return Inner2;
}
function rollUp<T>(mixins): new (...args) => T {
return mixins.reduce((acc, mixin) => mixin(acc), class Seed {});
}
class Example extends rollUp<Outer1 & Outer2>([Mixin1, Mixin2]) {
// Compiler will throw error when "notSame" is unimplemented
// Compiler DOES NOT throw error about non-implemented "same" member
}
Expected behavior:
Compiler should say that same is not implemented in regular class
Actual behavior:
Compiler does not throw error saying that same is not present in example class, despite throwing an error about notSame. It will throw an error, however, if the types of same are incompatible.