tannerntannern / ts-mixer

A small TypeScript library that provides tolerable Mixin functionality.
MIT License
379 stars 27 forks source link

Uncaught TypeError: Illegal invocation #1

Closed Baumgaer closed 5 years ago

Baumgaer commented 5 years ago

If you try to inherit from a native Element such as HTMLElement, then you get an Uncaught TypeError: Illegal invocation.

import { Mixin } from 'ts-mixer';
import { BaseController } from './../controllers/BaseController';

export class BaseComponent extends Mixin(HTMLElement, BaseController) {
    constructor() {
        super();
        ...

I think this can become the best solution for mixins. If you look for https://www.npmjs.com/package/ts-mixins you will see that there is the issue, that the first instance of my Controller is an instance of BaseComponent and later its an instance of a native HTMLElement. As a result, the constructor acts on the wrong object. (But if u use this package you must change HTMLElement and BaseController)

But this only by the way... Please think of it ;)

Try your awesome Mixins with Webcomponents... This is very important for at least me =)

tannerntannern commented 5 years ago

Hi @Eluminati, I was finally able to reproduce the issue you described within the test suite. Unfortunately, I don't have time to look into this right away, but I created an issue-1 branch with the scaffolding to reproduce the TypeError: Illegal invocation you described. (Check out test/bug-html-element.test.ts) If you or anyone else wants to contribute to that branch, it would be much appreciated. Otherwise, it may be a bit before I can resolve it.

tannerntannern commented 5 years ago

I apologize for the long delay. Given that WebComponents don't seem to have very wide support yet, this issue may be out of my control. Closing for now.