Skip to content

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

Open

Description

@AjiTae

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

Activity

  1. TechQuery commented on Sep 7, 2022

    @TechQuery

    At 2022, with TypeScript 4.8.2, this kind of codes:

    export function mixin() {
        abstract class Mixin {
            abstract test(): void
        }
        return Mixin;
    }

    will emit a declaration file as below:

    export declare function mixin(): abstract new () => {
        test(): void;
    };

    which can't hint library users to implement required properties.

    PS: the playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: classesBehavior of various `class` constructs, e.g. mixins or base classes

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions