microsoft / microsoft/TypeScript

Mixin abstract class: union of abstract propeties is not abstract.

Open
#39,752 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: classes
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.9.2

Search Terms: mixin abstract union

Expected behavior:
Union of abstract propeties is abstract property.

Actual behavior:
Union of abstract propeties is not abstract.

Related Issues:

Code

type Constructor = new (...args: any[]) => {};

class BaseClass {}

function AB<TBase extends Constructor>(Base: TBase) {
  abstract class AB extends Base {
    abstract a: number
    abstract b: number
  };
  return AB
}
function AC<TBase extends Constructor>(Base: TBase) {
  abstract class AC extends Base {
    abstract a: number
    abstract c: number
  };
  return AC
}

// should throw "Non-abstract class 'ShouldHavePropA' does not implement inherited abstract member 'a' from class ..."
class ShouldHavePropA extends AB(AC(BaseClass)) { 
    b = 1;
    c = 2;
}
Output
"use strict";
class BaseClass {
}
function AB(Base) {
    class AB extends Base {
    }
    ;
    return AB;
}
function AC(Base) {
    class AC extends Base {
    }
    ;
    return AC;
}
class ShouldHavePropA extends AB(AC(BaseClass)) {
    constructor() {
        super(...arguments);
        this.b = 1;
        this.c = 2;
    }
}

Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TypeScript 3.9.2 Playground link and reduce the provided mixin example to a focused compiler test. Trace how abstract properties are collected through the union of the AB and AC mixins. Done means the example reports that ShouldHavePropA fails to implement inherited abstract member a, with a regression test covering the behavior.

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
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.