Skip to content

Mix of mix cause error #34410

Closed
Closed
@shrinktofit

Description

@shrinktofit

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms:

  • Mixin composition
  • Recursive mixin

Code

type Constructor<T = any, A extends any[] = any[]> = new (...a: A) => T;

function CallbackInvokable<T extends Constructor>(base: T) {
    return class extends base {
        protected invoke(...args: any[]) { }
    };
}

function EventTargeted<T extends Constructor>(base: T) {
    // A event target should be callback-invoke-able.
    // Error: Type "{ new (...a: any[]): CallbackInvokable<T>.(Anonymous class); prototype: CallbackInvokable<any>.(Anonymous class); } & T" is not a constructor type.
    return class extends CallbackInvokable(base) {
        public emit (...args: any[]) {
            this.invoke(...args); // "invoke" doesn't exist on type (Anonymous Class).
        }
    };
}

class Empty {};
class Test extends CallbackInvokable(Empty) {}; // OK
class Resource extends EventTargeted(Empty) {}; // OK

Expected behavior:
No error reported.

Actual behavior:
Error reported, as commented above.

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions