google / google/closure-compiler

Missing JSC_MISSING_REQUIRE when importing `@interface` type via `goog.requireType` in a `goog.module`

Open
#3,851 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

The following code, [when compiled with `CHECK_REQUIRES`, produces a `JSC_MISSING_REQUIRE_IN_PROVIDES_FILE` warning](https://closure-compiler-debugger.appspot.com/#input0%3Dgoog.provide('Interface')%253B%250A%250A%252F**%2520%2540interface%2520*%252F%250AInterface%2520%253D%2520function()%2520%257B%257D%253B%250A%26input1%3Dgoog.requireType('Interface')%253B%250A%250A%252F**%2520%2540constructor%2520%2540implements%2520%257BInterface%257D%2520*%252F%250Afunction%2520Implementation()%2520%257B%257D%250A%26conformanceConfig%26externs%26refasterjs-template%26CHECK_TYPES%3Dtrue%26REWRITE_MODULES_BEFORE_TYPECHECKING%3Dtrue%26CHECK_REQUIRES%3Dtrue%26CLOSURE_PASS%3Dtrue%26PRESERVE_TYPE_ANNOTATIONS%3Dtrue%26PRETTY_PRINT%3Dtrue):

Parent:
```JS
goog.provide('Interface');

/** @interface */
Interface = function() {};
```

Child:
```
goog.requireType('Interface');

/** @constructor @implements {Interface} */
function Implementation() {}
```

Warnings:
```
input1:3:30: WARNING - [JSC_MISSING_REQUIRE_IN_PROVIDES_FILE] 'Interface' references a namespace which was not required by this file.
Please add a goog.require.
3| /** @constructor @implements {Interface} */
^^^^^^^^^

0 error(s), 1 warning(s), 55.5% typed
```

~~I believe this warning is spurious, because [it does not occur if you use `goog.require` instead of `goog.requireType`](https://closure-compiler-debugger.appspot.com/#input0%3Dgoog.provide('Interface')%253B%250A%250A%252F**%2520%2540interface%2520*%252F%250AInterface%2520%253D%2520function()%2520%257B%257D%253B%26input1%3Dgoog.require('Interface')%253B%250A%250A%252F**%2520%2540constructor%2520%2540implements%2520%257BInterface%257D%2520*%252F%250Afunction%2520Implementation()%2520%257B%257D%250A%26conformanceConfig%26externs%26refasterjs-template%26CHECK_TYPES%3Dtrue%26REWRITE_MODULES_BEFORE_TYPECHECKING%3Dtrue%26CHECK_REQUIRES%3Dtrue%26CLOSURE_PASS%3Dtrue%26PRESERVE_TYPE_ANNOTATIONS%3Dtrue%26PRETTY_PRINT%3Dtrue), even though the import is used only for type annotation, and [it does not occur if you use `goog.module` instead of `goog.provide`](https://closure-compiler-debugger.appspot.com/#input0%3Dgoog.module('Interface')%253B%250A%250A%252F**%2520%2540interface%2520*%252F%250Aconst%2520Interface%2520%253D%2520function()%2520%257B%257D%253B%250Aexports%2520%253D%2520Interface%253B%250A%26input1%3Dgoog.module('main')%253B%250Aconst%2520Interface%2520%253D%2520goog.requireType('Interface')%253B%250A%250A%252F**%2520%2540constructor%2520%2540implements%2520%257BInterface%257D%2520*%252F%250Afunction%2520Implementation()%2520%257B%257D%253B%250A%26conformanceConfig%26externs%26refasterjs-template%26CHECK_TYPES%3Dtrue%26REWRITE_MODULES_BEFORE_TYPECHECKING%3Dtrue%26CHECK_REQUIRES%3Dtrue%26CLOSURE_PASS%3Dtrue%26PRESERVE_TYPE_ANNOTATIONS%3Dtrue%26PRETTY_PRINT%3Dtrue).~~

EDIT: [Unfortunately, no error is emitted if you use `goog.require` instead of `goog.requireType`](https://closure-compiler-debugger.appspot.com/#input0%3Dgoog.provide('Interface')%253B%250A%250A%252F**%2520%2540interface%2520*%252F%250AInterface%2520%253D%2520function()%2520%257B%257D%253B%26input1%3Dgoog.require('Interface')%253B%250A%250A%252F**%2520%2540constructor%2520%2540implements%2520%257BInterface%257D%2520*%252F%250Afunction%2520Implementation()%2520%257B%257D%250A%26conformanceConfig%26externs%26refasterjs-template%26CHECK_TYPES%3Dtrue%26REWRITE_MODULES_BEFORE_TYPECHECKING%3Dtrue%26CHECK_REQUIRES%3Dtrue%26CLOSURE_PASS%3Dtrue%26PRESERVE_TYPE_ANNOTATIONS%3Dtrue%26PRETTY_PRINT%3Dtrue), even though the import is used only for type annotation, and [it does not occur if you use `goog.module` instead of `goog.provide`](https://closure-compiler-debugger.appspot.com/#input0%3Dgoog.module('Interface')%253B%250A%250A%252F**%2520%2540interface%2520*%252F%250Aconst%2520Interface%2520%253D%2520function()%2520%257B%257D%253B%250Aexports%2520%253D%2520Interface%253B%250A%26input1%3Dgoog.module('main')%253B%250Aconst%2520Interface%2520%253D%2520goog.requireType('Interface')%253B%250A%250A%252F**%2520%2540constructor%2520%2540implements%2520%257BInterface%257D%2520*%252F%250Afunction%2520Implementation()%2520%257B%257D%253B%250A%26conformanceConfig%26externs%26refasterjs-template%26CHECK_TYPES%3Dtrue%26REWRITE_MODULES_BEFORE_TYPECHECKING%3Dtrue%26CHECK_REQUIRES%3Dtrue%26CLOSURE_PASS%3Dtrue%26PRESERVE_TYPE_ANNOTATIONS%3Dtrue%26PRETTY_PRINT%3Dtrue) even though (from discussion below) it appears that one should be.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.