Skip to content

noImplicitOverride doesn't work if member is defined in multiple interfaces #45345

@frigus02

Description

@frigus02

Bug Report

The --noImplicitOverride check doesn't catch the case where an overridden member is defined in multiple interfaces.

We found this in code using Polymer. Compiling the following example with tsc file.ts --target esnext --moduleResolution node --noImplicitOverride gives the inlined error. But I would have expected the error as well for connectedCallback.

class XCustom extends PolymerElement {
    connectedCallback() { super.connectedCallback(); }
    disconnectedCallback() {  super.disconnectedCallback();  }
 // ~~~~~~~~~~~~~~~~~~~~ This member must have an 'override' modifier because it overrides a member in the base class 'PolymerElement'.
}

I boiled it down to the minimal example below.

🔎 Search Terms

noImplicitOverride, override, interface, multiple

🕗 Version & Regression Information

This is the behavior in every version I tried: 4.3.5, 4.4.0-beta

⏯ Playground Link

Playground link with relevant code

💻 Code

const ElementMixin: ElementMixinConstructor & PropertiesMixinConstructor = class {
  connectedCallback() {}
  disconnectedCallback() {}
};

interface ElementMixinConstructor {
  new(...args: any[]): ElementMixin;
}

interface ElementMixin {
  connectedCallback(): void;
}

interface PropertiesMixinConstructor {
  new(...args: any[]): PropertiesMixin;
}

interface PropertiesMixin {
  connectedCallback(): void;
  disconnectedCallback(): void;
}

export class TestElement extends ElementMixin {
  connectedCallback() {
    super.connectedCallback();
  }

  disconnectedCallback() {
    super.disconnectedCallback();
  }
}

🙁 Actual behavior

Compiled with --noImplicitOverride, this only requires override for disconnectedCallback but not for connectedCallback.

As soon as I remove connectedCallback from either the ElementMixin or PropertiesMixin interface, TypeScript requires override for it as well.

The behavior is the same for property members.

🙂 Expected behavior

I would expect TypeScript to require override for both disconnectedCallback and connectedCallback.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions