Skip to content
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

♻️ Migrate most of #core to pass TS typechecking #37141

Merged
merged 31 commits into from
Dec 9, 2021

Conversation

rcebulko
Copy link
Contributor

@rcebulko rcebulko commented Dec 7, 2021

Migrates most of the files under src/core from Closure type-checking to Typescript. Closure will no longer pass type-checking on many (most?) of these files. As a result, all Closure-based type-checking will stop passing (and so has been silenced in check-types.js). Later PRs will handle cleaning out legacy type-checking code.

Two #core directories are excluded: context and assert. context is intricate and isolated, so it can be migrated independently while this PR unblocks progress elsewhere in the repo. assert will be more involved because of differences in how CC and TS handle assertion annotations, so its type signatures are stubbed in this PR to be addressed in a later PR.

Some "globals" we access through the window object, which we rely on for some polyfills and testing scenarios. Because TS doesn't expect them to be on the window, there are corresponding TS definition files .d.ts which add these properties to the Window interface. Anything in a .d.ts file is TS-only logic that need to live outside of existing JS annotations. Mostly, they replace existing .extern.js files.

Files ending in .shame.d.ts contain "band-aids", such as type stubs, that allow type-checking to pass. One example is assert.shame.d.ts, which tells tsc to skip type-checking #core/assert for now and instead provides the type signatures it should expect.

Copy link
Member

@samouri samouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read through the first half. Will finish reviewing tomorrow morning. Looks great ⭐

src/core/constants/async-input.d.ts Show resolved Hide resolved
src/core/data-structures/weakref.d.ts Outdated Show resolved Hide resolved
src/core/dom/fullscreen.d.ts Outdated Show resolved Hide resolved
src/core/dom/layout/size-observer.js Show resolved Hide resolved
src/core/amp-config.d.ts Outdated Show resolved Hide resolved
src/core/assert.shame.d.ts Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Dec 7, 2021

This pull request introduces 15 alerts when merging 80a13bb into 3e8072d - view on LGTM.com

new alerts:

  • 15 for Ineffective parameter type

@lgtm-com
Copy link

lgtm-com bot commented Dec 8, 2021

This pull request introduces 7 alerts when merging 06e7268 into 6268ef3 - view on LGTM.com

new alerts:

  • 7 for Ineffective parameter type

@rcebulko rcebulko marked this pull request as ready for review December 8, 2021 19:18
@amp-owners-bot
Copy link

amp-owners-bot bot commented Dec 8, 2021

Hey @jridgewell! These files were changed:

src/core/3p-frame-messaging.js
src/core/amp-config.d.ts
src/core/assert.shame.d.ts
src/core/assert/index.js
src/core/constants/action-constants.js
src/core/constants/async-input.d.ts
src/core/constants/async-input.js
src/core/constants/loading-instructions.js
src/core/data-structures/curve.js
src/core/data-structures/dom-based-weakref.js
src/core/data-structures/finite-state-machine.js
src/core/data-structures/lru-cache.js
+84 more

@rcebulko
Copy link
Contributor Author

rcebulko commented Dec 8, 2021

@samouri bumping this

@samouri
Copy link
Member

samouri commented Dec 9, 2021

Do you know what all of the bundle size changes are from?

Copy link
Member

@samouri samouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work like usual

build-system/tasks/check-types.js Show resolved Hide resolved
src/compiler/types.d.ts Show resolved Hide resolved
src/core/constants/action-constants.js Show resolved Hide resolved
src/core/constants/async-input.d.ts Show resolved Hide resolved
src/core/data-structures/weakref.d.ts Show resolved Hide resolved
src/core/types/function/index.js Show resolved Hide resolved
src/core/types/object/index.js Show resolved Hide resolved
// obfuscated.
// TODO(rcebulko): Closure Compiler used this and the @dict annotation to check
// that properties are only accessed using bracket notation. We need to
// verify this works with TypeScript/esbuild.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot enforce this guarantee unless we write a custom script via the new TS API.
That said, I don't think fields get dangerously obfuscated like they did with CC... so this is not really an issue.

cc @jridgewell

src/core/types/object/json.js Show resolved Hide resolved
src/core/window/interface.js Outdated Show resolved Hide resolved
@rcebulko rcebulko enabled auto-merge (squash) December 9, 2021 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants