Skip to content

Mix of mix cause error #34410

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

Closed
shrinktofit opened this issue Oct 15, 2019 · 3 comments
Closed

Mix of mix cause error #34410

shrinktofit opened this issue Oct 15, 2019 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@shrinktofit
Copy link

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:

@raymondfeng
Copy link

Is it a duplicate of #33739?

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 17, 2019
@RyanCavanaugh
Copy link
Member

See #13807 and its related suggestions

@boconnell
Copy link

FWIW this seems more like a dupe of #32080 than #13807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants