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

feat(menu-surface): Convert JS to TypeScript #4273

Merged
merged 52 commits into from
Feb 5, 2019

Conversation

acdvorak
Copy link
Contributor

@acdvorak acdvorak commented Jan 19, 2019

Refs #4225

@codecov-io
Copy link

codecov-io commented Jan 19, 2019

Codecov Report

Merging #4273 into feat/typescript will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##           feat/typescript    #4273      +/-   ##
===================================================
+ Coverage            98.36%   98.45%   +0.09%     
===================================================
  Files                   93       93              
  Lines                 5736     5747      +11     
  Branches               778      775       -3     
===================================================
+ Hits                  5642     5658      +16     
+ Misses                  94       89       -5
Impacted Files Coverage Δ
packages/mdc-menu/foundation.js 83.87% <ø> (ø) ⬆️
packages/mdc-menu/index.js 100% <ø> (ø) ⬆️
packages/mdc-select/index.js 98.34% <ø> (ø) ⬆️
packages/mdc-menu-surface/util.ts 100% <100%> (ø)
packages/mdc-menu-surface/foundation.ts 100% <100%> (ø)
packages/mdc-menu-surface/index.ts 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 869e44c...86cfdad. Read the comment docs.

@mdc-web-bot
Copy link
Collaborator

All 758 screenshot tests passed for commit 7b1d930 vs. feat/typescript! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 758 screenshot tests passed for commit 6324518 vs. feat/typescript! 💯🎉

@acdvorak acdvorak changed the title chore(menu-surface): Convert JS to TypeScript feat(menu-surface): Convert JS to TypeScript Jan 22, 2019
packages/mdc-menu-surface/adapter.ts Show resolved Hide resolved
packages/mdc-menu-surface/adapter.ts Outdated Show resolved Hide resolved
packages/mdc-menu-surface/adapter.ts Outdated Show resolved Hide resolved
packages/mdc-menu-surface/adapter.ts Outdated Show resolved Hide resolved
packages/mdc-menu-surface/foundation.ts Show resolved Hide resolved
packages/mdc-menu-surface/index.ts Outdated Show resolved Hide resolved
packages/mdc-menu-surface/index.ts Outdated Show resolved Hide resolved
this.foundation_.setQuickOpen(quickOpen);
}
getDefaultFoundation(): MDCMenuSurfaceFoundation {
// TODO(acdvorak): Should we change the type of root_ to HTMLElement? What other kind of element could it be?
Copy link
Contributor

Choose a reason for hiding this comment

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

Ya I was reading the differences between element and htmlelement. HTMLElement is a subset of Element. So element Element could be XML/SVG/HTML. I think in our case it will never be an XML element. I think its most accurate to be HTMLElement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only situation I can think of where we might have a non-HTML element is ripples on SVG icons. However, SVGElement appears to have most of the same properties and methods as HTMLElement (style, querySelector(), etc.), so it's probably safe to update MDCComponent's root_ property type to HTMLElement.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I remember when we were annotating for Closure compiler, HTMLElement was more problematic, possibly due to many DOM APIs applying more generically to (and returning) Elements. I'd be curious if we end up running into similar problems here or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, I'm going to stick with Element and do type assertions where necessary (e.g., this.root_.style). Seems like the least risky option.

packages/mdc-menu-surface/index.ts Outdated Show resolved Hide resolved
packages/mdc-menu-surface/util.ts Outdated Show resolved Hide resolved
@mdc-web-bot
Copy link
Collaborator

All 758 screenshot tests passed for commit 913f607 vs. feat/typescript! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 758 screenshot tests passed for commit f55703f vs. feat/typescript! 💯🎉

Copy link
Contributor

@moog16 moog16 left a comment

Choose a reason for hiding this comment

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

I think it looks good as is. But after chatting with @mmalerba we need to add some new properties to the tsconfig. Could you add strict: true to the tsconfig.json file and see what new errors pop up? I'm working on finding out what else we need to add.

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 63845ba vs. feat/typescript! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit f00a4aa vs. feat/typescript! 💯🎉

packages/mdc-menu-surface/README.md Outdated Show resolved Hide resolved
packages/mdc-menu-surface/README.md Outdated Show resolved Hide resolved
BOTTOM_END = CornerBit.BOTTOM | CornerBit.RIGHT | CornerBit.FLIP_RTL, // tslint:disable-line:no-bitwise
}

interface MenuDimensions {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is constants.ts where we've been putting this sort of thing? It seems like an odd idea for interfaces to be here. Would putting them in adapter.ts make more sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went back and forth on that myself. @moog16 and I decided to move them from adapter.ts to constants.ts because the constants file already has enums, which feel "type-y".

We were thinking that any type whose name beings with MDC (i.e., index, foundation, and adapter) should have its own file; everything else would go in constants.js. It feels simple and straightforward to me.

We could conceivably create an entirely separate file just for interfaces and type definitions, but that might be overkill.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO interfaces feel more type-y than enums (which are much more value-y than type-y at least the way we're using them), which is why I thought of adapter.ts (also since most of the interfaces currently defined in constants.ts are required by the adapter anyway).

How many components have we done this with so far?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed offline, we're going to create a new types.ts file for interfaces and other type definitions that don't belong in constants.ts or adapter.ts.

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 56b75ac vs. feat/typescript! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit d45afea vs. feat/typescript! 💯🎉

@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 9c76326 vs. feat/typescript! 💯🎉

packages/mdc-menu-surface/index.ts Show resolved Hide resolved
packages/mdc-menu/README.md Outdated Show resolved Hide resolved
packages/mdc-menu/index.js Outdated Show resolved Hide resolved
packages/mdc-menu/index.js Outdated Show resolved Hide resolved
@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit b964b75 vs. feat/typescript! 💯🎉

acdvorak added a commit that referenced this pull request Feb 4, 2019
Accepting `string` values implies that we support all valid CSS units (`em`, `rem`, `%`, etc.), but in truth we only support `px`.

Changing the type of the properties from `string` to `number` makes this clearer, and also simplifies converting the package to TypeScript in PR #4273.

BREAKING CHANGE: `MDCMenuSurfaceAdapter.setPosition()` now expects an object with properties of type `number` rather than `string`. E.g., `setPosition({top: '5px', left: '10px'})` is now `setPosition({top: 5, left: 10})`.
acdvorak added a commit that referenced this pull request Feb 4, 2019
Accepting `string` values implies that we support all valid CSS units (`em`, `rem`, `%`, etc.), but in truth we only support `px`.

Changing the type of the properties from `string` to `number` makes this clearer, and also simplifies converting the package to TypeScript in PR #4273.

BREAKING CHANGE: `MDCMenuSurfaceAdapter.setPosition()` now expects an object with properties of type `number` rather than `string`. E.g., `setPosition({top: '5px', left: '10px'})` is now `setPosition({top: 5, left: 10})`.
@mdc-web-bot
Copy link
Collaborator

All 621 screenshot tests passed for commit 86cfdad vs. feat/typescript! 💯🎉

acdvorak added a commit that referenced this pull request Feb 5, 2019
…ues (#4351)

Accepting `string` values implies that we support all valid CSS units (`em`, `rem`, `%`, etc.), but in truth we only support `px`.

Changing the type of the properties from `string` to `number` makes this clearer, and also simplifies converting the package to TypeScript in PR #4273.

BREAKING CHANGE: `MDCMenuSurfaceAdapter.setPosition()` now expects an object with properties of type `number` rather than `string`. E.g., `setPosition({top: '5px', left: '10px'})` is now `setPosition({top: 5, left: 10})`.
@kfranqueiro kfranqueiro dismissed moog16’s stale review February 5, 2019 20:36

Review comments have been resolved and Matt's not back until tomorrow

@acdvorak acdvorak merged commit a2ac8bc into feat/typescript Feb 5, 2019
@acdvorak acdvorak deleted the feat/typescript--menu-surface branch February 5, 2019 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants