Skip to content

@override no longer copies typing information #4275

@vapier

Description

@vapier

this seems to be a regression between v20201102 & v20201207. here's an example:

class foo {
  /**
   * Delete everything in this storage.
   *
   * @return {!Promise<void>} When clearing has completely.
   */
  async clear() {}
}

class fooBar extends foo {
  /** @override */
  async clear() {
    return new Promise((resolve) => {
      resolve();
    });
  }
}

in version v20201102 and older, we see no errors:

$ closure-compiler --version
Closure Compiler (http://github.com/google/closure-compiler)
Version: v20201102
$ closure-compiler --jscomp_error='*' --checks-only test.js 

but after upgrading to v20201207 (v20250820 behaves the same), we see:

$ closure-compiler --version
Closure Compiler (http://github.com/google/closure-compiler)
Version: v20201207
$ closure-compiler --jscomp_error='*' --checks-only test.js 
test.js:12:8: ERROR - [JSC_MISSING_RETURN_JSDOC] Function with non-trivial return must have JSDoc indicating the return type. Please see go/tsjs-problematic-patterns for why @overrides require explicit @return types..
  12|   async clear() {
              ^^^^^^^^^
  13|     return new Promise((resolve) => {
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
  15|     });
      ^^^^^^^
  16|   }
      ^^^

1 error(s), 0 warning(s), 94.8% typed

copying the typing info by hand makes it go away, but the documentation says this isn't necessary:

https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#override
If no other annotations are included, the method or property automatically inherits annotations from its superclass.

i'm guessing this is commit 777ab36 by @rishipal. the associated internal bug suggests this change was made because of a bug in Clutz -- it didn't actually implement the @override semantics. i grok that maybe for internal Google code, since JS->TS was a temporary migration, forcing people to duplicate typing was reasonable, but i don't know why that policy decision was made in the external closure-compiler version.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions