-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use goog.requireType
when importing interfaces (etc.)
#5343
Conversation
Interfaces have no code, so should never be referred to outside of (JSDoc) comments, and so the modules that define only interfaces never need to be goog.require'd - goog.requireType is always sufficient. This commit fixes imports of all modules whose name matches /(.*\.)?I[A-Z]*/ - i.e., the hungarian-notation named ones in core/interfaces/.
Where a module is imported only to used in JSDoc comments it can (and should) be goog.requireType'd instead of goog.require'd.
There were a few cases where modules were being imported with goog.require (because they are referred to in code, not just JSDoc comments) but were prefaced by a spurious eslint suppress. Remove these, restoring the invariant that an import gets an eslint if and only if it is a requireType.
5906401
to
be0f6ed
Compare
Rebased to fix conflicts in |
Continuation of a conversation from #5317:
Monica got this requirement from me. I know that I said this because of compiler errors or warnings that I was getting from using I think that those were warnings that I got when I added the |
stricterMissingRequire has been superceded by missingRequire, and now causes a Java null pointer exception if supplied.
@rachel-fenichel: thanks for copying over the discussion.
That is super interesting. Ok, short summary of what I have learned this morning:
So I think the changes to already-migrated files are fine. For the not-yet-migrated ones, I could back out the change for now, but I think it's probably better to leave it in so that whoever does the migration doesn't need to remember to do it then. |
I retain my standard skepticism about whether it's a compiler bug--but since you were able to reproduce the errors in the unconverted files, and show that they don't happen in the converted files, this seems safe. Approved. |
I've filed google/closure-compiler#3851; we'll see what they say. |
It seems that you are correct and I am wrong: there is a compiler bug, but apparently the bug is that no error message is issued when |
The basics
goog_module
goog_module
npm test
.The details
Resolves
Related to #5026
Proposed Changes
Use
goog.requireType
instead ofgoog.require
when:Also ensure that an import is marked
/* eslint-disable-next-line no-unused-vars */
if and only if it is agoog.requireType
.Reason for Changes
Interfaces have no code, so should never be referred to outside of (JSDoc) comments, and so the modules that define only interfaces never need to be
goog.require
'd—goog.requireType
is always sufficient. This is also true of other non-interface types which appear only in comments.Test Coverage
npm test
; all tests passed.npm run test:compile:advanced
(with some local temporary fixes to un-break it); no increase in number of warnings generated.Additional Information
I've applied this change to all the
I*
modules (hungarian notation FTW!)