Skip to content

Commit

Permalink
Update mixins to avoid compilation issues
Browse files Browse the repository at this point in the history
The following 2 issues appears internally:
microsoft/TypeScript#15870
microsoft/TypeScript#9944

Change-Id: I60b669846447ff7f54e7b0f741402333c2b59653
  • Loading branch information
gdmfilippov authored and lucamilanesio committed Nov 10, 2020
1 parent 2423c01 commit cd2ccb2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {htmlTemplate} from './gr-autocomplete-dropdown_html';
import {KeyboardShortcutMixin} from '../../../mixins/keyboard-shortcut-mixin/keyboard-shortcut-mixin';
import {IronFitMixin} from '../../../mixins/iron-fit-mixin/iron-fit-mixin';
import {customElement, property, observe} from '@polymer/decorators';
import {IronFitBehavior} from '@polymer/iron-fit-behavior/iron-fit-behavior';

// TODO(TS): Update once GrCursorManager is upated
export interface GrAutocompleteDropdown {
Expand Down Expand Up @@ -55,7 +56,8 @@ interface Item {
export class GrAutocompleteDropdown extends IronFitMixin(
KeyboardShortcutMixin(
GestureEventListeners(LegacyElementMixin(PolymerElement))
)
),
IronFitBehavior as IronFitBehavior
) {
static get template() {
return htmlTemplate;
Expand Down
4 changes: 3 additions & 1 deletion polygerrit-ui/app/elements/shared/gr-overlay/gr-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {PolymerElement} from '@polymer/polymer/polymer-element';
import {htmlTemplate} from './gr-overlay_html';
import {IronOverlayMixin} from '../../../mixins/iron-overlay-mixin/iron-overlay-mixin';
import {customElement, property} from '@polymer/decorators';
import {IronOverlayBehavior} from '@polymer/iron-overlay-behavior/iron-overlay-behavior';

const AWAIT_MAX_ITERS = 10;
const AWAIT_STEP = 5;
Expand All @@ -34,7 +35,8 @@ declare global {

@customElement('gr-overlay')
export class GrOverlay extends IronOverlayMixin(
GestureEventListeners(LegacyElementMixin(PolymerElement))
GestureEventListeners(LegacyElementMixin(PolymerElement)),
IronOverlayBehavior as IronOverlayBehavior
) {
static get template() {
return htmlTemplate;
Expand Down
13 changes: 12 additions & 1 deletion polygerrit-ui/app/mixins/iron-fit-mixin/iron-fit-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,19 @@ import {Constructor} from '../../utils/common-util';

// The mixinBehaviors clears all type information about superClass.
// As a workaround, we define IronFitMixin with correct type.
// Due to the following issues:
// https://github.com/microsoft/TypeScript/issues/15870
// https://github.com/microsoft/TypeScript/issues/9944
// we have to import IronFitBehavior in the same file where IronFitMixin
// is used. To ensure that this import can't be avoided, the second parameter
// is added. Usage example:
// class Element extends IronFitMixin(PolymerElement, IronFitBehavior as IronFitBehavior)
// The code 'IronFitBehavior as IronFitBehavior' required, becuase IronFitBehavior
// defined as an object, not as IronFitBehavior instance.

export const IronFitMixin = <T extends Constructor<PolymerElement>>(
superClass: T
superClass: T,
_: IronFitBehavior
): T & Constructor<IronFitBehavior> =>
// TODO(TS): mixinBehaviors in some lib is returning: `new () => T` instead
// which will fail the type check due to missing IronFitBehavior interface
Expand Down
17 changes: 14 additions & 3 deletions polygerrit-ui/app/mixins/iron-overlay-mixin/iron-overlay-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,20 @@ import {Constructor} from '../../utils/common-util';

// The mixinBehaviors clears all type information about superClass.
// As a workaround, we define IronOverlayMixin with correct type.
// Due to the following issues:
// https://github.com/microsoft/TypeScript/issues/15870
// https://github.com/microsoft/TypeScript/issues/9944
// we have to import IronOverlayBehavior in the same file where IronOverlayMixin
// is used. To ensure that this import can't be avoided, the second parameter
// is added. Usage example:
// class Element extends IronOverlayMixin(PolymerElement, IronOverlayBehavior as IronOverlayBehavior)
// The code 'IronOverlayBehavior as IronOverlayBehavior' required, because
// IronOverlayBehavior defined as an object, not as IronOverlayBehavior instance.
export const IronOverlayMixin = <T extends Constructor<PolymerElement>>(
superClass: T
superClass: T,
_: IronOverlayBehavior
): T & Constructor<IronOverlayBehavior> =>
// TODO(TS): mixinBehaviors in some lib is returning: `new () => T` instead
// which will fail the type check due to missing IronOverlayBehavior interface
// TODO(TS): mixinBehaviors in some lib is returning: `new () => T`
// instead which will fail the type check due to missing
// IronOverlayBehavior interface
mixinBehaviors([IronOverlayBehavior], superClass) as any;

0 comments on commit cd2ccb2

Please sign in to comment.