-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Conversation
All 758 screenshot tests passed for commit 75cb9ba vs. |
All 758 screenshot tests passed for commit 97fed6f vs. |
packages/mdc-ripple/adapter.ts
Outdated
} | ||
|
||
export default MDCRippleAdapter; | ||
export {Point}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export {MDCRippleAdapter as default, MDCRippleAdapter, Point};
packages/mdc-ripple/adapter.ts
Outdated
|
||
containsEventTarget(target: EventTarget | null): boolean; | ||
|
||
registerInteractionHandler<K extends keyof GlobalEventHandlersEventMap>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh fancy! I didn't know this was a thing :)
I'd suggest putting some aliases in a common place somewhere to make the types more readable:
type EventType = keyof GlobalEventHandlersEventMap;
type SpecificEventListener<K extends EventType> = (evt: GlobalEventHandlersEventMap[K]) => void;
Then these would look like:
registerInteractionHandler<E extends EventType>(evtType: E, handler: SpecificEventListener<E>): void;
registerResizeHandler(handler: SpecificEventListener<'resize'>): void;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yaa I like that 👍
All 758 screenshot tests passed for commit 79542ed vs. |
packages/mdc-ripple/util.ts
Outdated
} | ||
|
||
interface CssWindow extends Window { | ||
CSS?: CssObject; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS has a type CSS
which is equivalent to your CssObject
, it's just not on the Window
for some reason. You might be able to make a file of type fixes somewhere, like this:
declare interface Window { CSS: CSS; }
You could also add a fix for the msMatchesSelector
thing, might be nicer than having to invent your own types and cast them everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya we need to invent a place for these global types. Maybe the correct place is in mdc-dom package. I'm going to add it to the index.ts
for now. We can decide for a better place as this PR evolves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I found that this works:
declare global {
interface Window {
CSS: CSS;
}
}
globals seems like a last ditch effort. Is that a valid pattern? Or is there a better way of accomplishing this?
typings/events.d.ts
Outdated
* THE SOFTWARE. | ||
*/ | ||
|
||
declare type EventType = keyof GlobalEventHandlersEventMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for these ones you might want to leave them in a .ts
file and export them so users can use them too
Codecov Report
@@ Coverage Diff @@
## feat/typescript #4300 +/- ##
===================================================
- Coverage 98.57% 98.46% -0.12%
===================================================
Files 92 92
Lines 5674 5718 +44
Branches 760 768 +8
===================================================
+ Hits 5593 5630 +37
- Misses 81 88 +7
Continue to review full report at Codecov.
|
packages/mdc-menu-surface/adapter.ts
Outdated
@@ -0,0 +1,131 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know how this ended up here...removing
All 758 screenshot tests passed for commit 7abb9d2 vs. |
packages/mdc-ripple/adapter.ts
Outdated
|
||
deregisterDocumentInteractionHandler<K extends EventType>(evtType: K, handler: SpecificEventListener<K>): void; | ||
|
||
registerResizeHandler(handler: (evt: GlobalEventHandlersEventMap['resize']) => void): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpecificEventListener<'resize'>
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
I signed it |
All 758 screenshot tests passed for commit b675f5c vs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed the boat prior to this being merged but I have a few questions and a couple of cleanup comments.
if (typeof supportsCssVariables_ === 'boolean' && !forceRefresh) { | ||
return supportsCssVariables; | ||
return Boolean(supportsCssVariables_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this really need this cast? The if
is already confirming it's boolean
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS Compiler was complaining without the case before. I think what I did was copy from rachel's CL and rewrote the logic.
} | ||
|
||
const explicitlySupportsCssVars = windowObj.CSS.supports('--css-vars', 'yes'); | ||
const {CSS} = windowObj; | ||
const explicitlySupportsCssVars = CSS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CSS &&
here and below seem redundant here because it's already checked above... is TS complaining without this?
} | ||
|
||
const explicitlySupportsCssVars = windowObj.CSS.supports('--css-vars', 'yes'); | ||
const {CSS} = windowObj; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the new typings
files automatically get picked up by tsc with no configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct if we don't define files
or includes
in the tsconfig.json file, TS defaults to finding all .d.ts
files within the tsconfig's root directory.
https://www.typescriptlang.org/docs/handbook/tsconfig-json.
If the "files" and "include" are both left unspecified, the compiler defaults to including all TypeScript (.ts, .d.ts and .tsx) files in the containing directory and subdirectories except those excluded using the "exclude" property. JS files (.js and .jsx) are also included if allowJs is set to true. If the "files" or "include" properties are specified, the compiler will instead include the union of the files included by those two properties. Files in the directory specified using the "outDir" compiler option are excluded as long as "exclude" property is not specified.
*/ | ||
function getMatchesProperty(HTMLElementPrototype) { | ||
/** Gets the matches function from an element. */ | ||
export function getMatchesFunction(htmlElementPrototype: HTMLElement): (selector: string) => boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this function exist? It did not exist before, appears to be unused, and differs in behavior than getMatchesProperty
(it incorrectly prefers vendor-prefixed versions, and it's incorrectly returning the webkit-prefixed version in the ms-prefixed branch).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also something I picked up from Rachel's CL...I didn't check it for usages. Good catch
*/ | ||
function getNormalizedEventCoords(ev, pageOffset, clientRect) { | ||
export function getNormalizedEventCoords( | ||
ev: Event | undefined, pageOffset: Point, clientRect: ClientRect): Point { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we allowing undefined here? It was not allowed to be undefined in the previous definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in foundation.ripple the activationEvent is defaulted to undefined
. It then trickled to this function. Not sure what else to default the defaultActivationState
.
ev = /** @type {!TouchEvent} */ (ev); | ||
normalizedX = ev.changedTouches[0].pageX - documentX; | ||
normalizedY = ev.changedTouches[0].pageY - documentY; | ||
const e = ev as TouchEvent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we give this variable a more descriptive name like touchEvent
rather than an even more abbreviated name? Single-letter variables are notoriously harder to search usages of.
normalizedX = e.pageX - documentX; | ||
normalizedY = e.pageY - documentY; | ||
} | ||
if (normalizedX === undefined || normalizedY === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually possible to happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like that was added from an original PR to test typescript. So I think it is a relic from an older version of TS complaining. Checked with Rachel and it is not needed. Removing.
get unbounded() { | ||
return this.unbounded_; | ||
disabled = false; | ||
root_: Element = this.root_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly dumb question: is the assignment here actually doing anything or is it just assigning this.root_
to itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is just assigning it to itself. Without that line, this
is not of type RippleCapableSurface
. This causes line 116 to complain:
getDefaultFoundation(): MDCRippleFoundation {
return new MDCRippleFoundation(MDCRipple.createAdapter(this));
}
Should I add a comment?
related #4225