首页 > 解决方案 > 如何在 Typescript 中编写 Polymer3 Mixin

问题描述

如果我尝试在 Typescript 中编写具有自己属性的 polymer3 mixin,它将失败并出现以下错误:

xxx 错误地扩展了 yyy

属性类型不兼容

我已经这样做了但在 Typescript 中)有没有办法在没有 ts-ignore 的情况下解决?

示例代码:

function VisuElement<B extends Constructor<any>>(base: B) {
    return class extends base {
        constructor(...args: any[]) {
            super();
            this._ve = true;
            this._veBindings = [];
        }

        static get properties() {
            return {
                unbindOnUnload: Boolean //Needed when a Element is created via a Dom repeat
            }
        }
    }
}

用法:

class VisuSignalValueDisplay extends VisuElement(PolymerElement) {
    static get template() {
        return html`
        <div></div>
`;
    }

    static get is() { return 'visu-signal-value-display'; }

    static get properties() {
        return {
            signalName: String
        };
    }
}

标签: typescriptecmascript-6polymer-3.x

解决方案


推荐阅读