Migrate check-types from closure to tsc#35243
Closed
samouri wants to merge 4 commits intoampproject:mainfrom
Closed
Migrate check-types from closure to tsc#35243samouri wants to merge 4 commits intoampproject:mainfrom
samouri wants to merge 4 commits intoampproject:mainfrom
Conversation
|
This pull request introduces 1 alert when merging f11f3a8 into 09c92d8 - view on LGTM.com new alerts:
|
|
This pull request introduces 1 alert when merging 5a1eeeb into 09c92d8 - view on LGTM.com new alerts:
|
Member
Author
|
Completed in #37141 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
There are various inconsistencies between TS and Closure that mean this change isn't as simple as flipping a switch.
From what I can tell, TS seems to catch more and is more pedantic around denying implicit
any, and Closure is smarter about knowing an item is not null after a devAssert.Overall there are ~250 errors in
src/core/**/*.js(the only type checked code), most of which seem trivially solvable.Some examples of changes we'll need to make:
1. Convert externs to .d.ts
This is relatively straightforward. For example with error.extern.js we can change it to
2. While loop array.pop() iteration
Closure is more intelligent about determining that an element cannot be null, specifically for the pattern called out here: microsoft/TypeScript#23405. We'll need to work around it for TS. Likely by taking advantage of type casting and
NonNullable<typeof arr[0]>3. File path types
Closure supporting typedefs references in other files. I'm not sure TS can do that unless the variables are in scope (imported) or are declared globally.
4. asserts
Closure allows our
devAssertto both return a value and imply that the value is no longer null everywhere after it.TS supports a notion Utility types which are allowed within JSDoc as well. We can convert all of our assertions to use this. Instead of returning
T, our asserts should returnNonnullable<T>. Note that this doesn't completely solve it, since there is still a leftover issue.5. Incorrect/weird inference
TS will sometimes prioritize a node_modules based type instead of a
DOMbased one. For example, usage ofsetTimeoutsometimes ends up referring to theNode.jsone instead ofWindow.setTimeoutwhich has an incompatible type definition. A hacky workaround is to convert the call intowindow.setTimeout, but ideally we could completely exclude certain types from the compilation (i.e.node_modules/@types/node/**/*.ts)