Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AjiTae opened this issue Jul 26, 2020 · 1 comment
Open

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

AjiTae opened this issue Jul 26, 2020 · 1 comment
Labels
Bug A bug in TypeScript
Milestone

Comments

@AjiTae
Copy link

AjiTae commented Jul 26, 2020

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

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 17, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 17, 2020
@TechQuery
Copy link

TechQuery commented Sep 7, 2022

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
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants