Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(list): ts conversion #4334

Merged
merged 22 commits into from
Feb 6, 2019
Merged

feat(list): ts conversion #4334

merged 22 commits into from
Feb 6, 2019

Conversation

moog16
Copy link
Contributor

@moog16 moog16 commented Feb 1, 2019

related #4225

@codecov-io
Copy link

codecov-io commented Feb 1, 2019

Codecov Report

Merging #4334 into feat/typescript will increase coverage by <.01%.
The diff coverage is 98.79%.

Impacted file tree graph

@@                Coverage Diff                 @@
##           feat/typescript   #4334      +/-   ##
==================================================
+ Coverage            98.39%   98.4%   +<.01%     
==================================================
  Files                   93      93              
  Lines                 5803    5819      +16     
  Branches               784     783       -1     
==================================================
+ Hits                  5710    5726      +16     
  Misses                  92      92              
  Partials                 1       1
Impacted Files Coverage Δ
packages/mdc-dom/ponyfill.ts 100% <ø> (ø) ⬆️
packages/mdc-list/foundation.ts 100% <100%> (ø)
packages/mdc-list/index.ts 98.5% <97.67%> (ø)

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 f595a99...696fa69. Read the comment docs.

@mdc-web-bot
Copy link
Collaborator

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

@mdc-web-bot
Copy link
Collaborator

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

@mdc-web-bot
Copy link
Collaborator

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

@@ -98,7 +98,7 @@ class MDCComponent<FoundationType extends MDCFoundation> {
* Fires a cross-browser-compatible custom event from the component root of the given type,
* with the given data.
*/
emit(evtType: string, evtData: object, shouldBubble = false) {
emit(evtType: string, evtData: number | object, shouldBubble = false) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe you can use unknown instead of number | object here. It will allow you to accept number, object, string, etc. but you won't be able to do things to it (e.g. access properties), which makes it safe, unlike any. (read more here)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the suggestion!

Ken and I thought it might be better to make this method generic, so that the caller can express the exact type of evtData. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah you could do that too. I'm not sure specifying the type really does anything for you though, it doesn't get saved on the instance or used in the return value, it just gets handed off to browser APIs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@acdvorak, you mean emit<T = object>(evtType: string, evtData: T, shouldBubble = false)? I think it is better than just unknown, but to @mmalerba's point its not "safer" than it being unknown.

Copy link
Contributor

@acdvorak acdvorak Feb 6, 2019

Choose a reason for hiding this comment

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

Fair point 😄

However, emit<T extends object>() has the advantage that it prevents primitive types like number from being passed to evtData, which we were previously doing in MDCList (see #4356).

To avoid backward compatibility issues in the future, we should always pass some kind of object so that we can easily add more properties.

OOC, what's the difference between
emit<T extends object>() and emit<T = object>()?

Edit: emit<T = object>() is incorrect. It sets the default type to object, but still allows primitive types like number, whereas we want to disallow primitives.
So emit<T extends object>() is indeed correct.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to disallow primitives, you can just do eventData: object. It looked from the existing code like you wanted to be able to pass objects or numbers (or I assumed anything else which is why I suggested unknown)

Copy link
Contributor

Choose a reason for hiding this comment

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

True, but making it generic will also help protect us against accidentally passing the wrong data. E.g.:

interface Foo {
  foo: number;
}

interface Bar {
  bar: string;
}

this.emit<Foo>('whatever', {bar: '...'}); // Error
this.emit('whatever', {bar: '...'}); // "Valid", but incorrect

@mdc-web-bot
Copy link
Collaborator

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

@mdc-web-bot
Copy link
Collaborator

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

@mdc-web-bot
Copy link
Collaborator

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

@moog16
Copy link
Contributor Author

moog16 commented Feb 6, 2019 via email

@mdc-web-bot
Copy link
Collaborator

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

@mdc-web-bot
Copy link
Collaborator

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

@mdc-web-bot
Copy link
Collaborator

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

@acdvorak acdvorak self-assigned this Feb 6, 2019
@mdc-web-bot
Copy link
Collaborator

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

Copy link
Contributor

@acdvorak acdvorak left a comment

Choose a reason for hiding this comment

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

LGTM!

@mdc-web-bot
Copy link
Collaborator

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

@acdvorak acdvorak merged commit 0b28992 into feat/typescript Feb 6, 2019
@acdvorak acdvorak deleted the feat/list-ts branch February 6, 2019 06:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants