microsoft / microsoft/TypeScript
Intersection type of abstract classes does not throw error if same member exists in multiple abstract classes
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked TypeScript Playground reproduction and compare the diagnostics for same and notSame in the Example class. Trace the compiler's handling of abstract members produced by the intersection and mixins; done means the missing same member is reported while the existing notSame diagnostic remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100