Skip to content

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

Merged
rcebulko merged 31 commits intoampproject:mainfrom
rcebulko:core-ts
Dec 9, 2021
Merged

♻️ Migrate most of #core to pass TS typechecking#37141
rcebulko merged 31 commits intoampproject:mainfrom
rcebulko:core-ts

Conversation

@rcebulko
Copy link
Copy Markdown
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
Copy Markdown
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 ⭐

@lgtm-com
Copy link
Copy Markdown

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
Copy Markdown

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 requested a review from rileyajones December 8, 2021 19:09
@rcebulko rcebulko marked this pull request as ready for review December 8, 2021 19:18
@amp-owners-bot
Copy link
Copy Markdown

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
Copy Markdown
Contributor Author

rcebulko commented Dec 8, 2021

@samouri bumping this

@samouri
Copy link
Copy Markdown
Member

samouri commented Dec 9, 2021

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

Copy link
Copy Markdown
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

// 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
Copy Markdown
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

@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