refactor(tests): reduce TypeScript errors#10344
Conversation
| expect(chipSelectSpy2).toHaveReceivedEventTimes(0); | ||
|
|
||
| await chip5.setAttribute("selected", true); | ||
| await chip5.toggleAttribute("selected", true); |
There was a problem hiding this comment.
This is a boolean attribute
Before it was being set here to selected="true"
| let comboboxItem: E2EElement; | ||
| let itemNestedLi: E2EElement; | ||
| let closeEvent: Promise<void>; | ||
| let closeEvent: Promise<unknown>; |
There was a problem hiding this comment.
Stencil's waitForEvent has return type Promise<any> so this worked.
In Lumina, the return type is Promise<SerializedEvent>.
(at runtime, Stencil's waitForEvent also returned Promise, but they didn't publicly expose the SerializedEvent type)
| */ | ||
| @Event({ cancelable: false }) | ||
| calciteInternalListItemGroupDefaultSlotChange: EventEmitter<DragEvent>; | ||
| calciteInternalListItemGroupDefaultSlotChange: EventEmitter<void>; |
There was a problem hiding this comment.
it didn't actually emit this type, and no one was listening for it to emit this type
| aria-valuemax={isDeterminate ? 100 : undefined} | ||
| aria-valuemin={isDeterminate ? 0 : undefined} | ||
| aria-valuenow={isDeterminate ? valueNow : undefined} | ||
| aria-valuemax={isDeterminate ? "100" : undefined} |
There was a problem hiding this comment.
Stencil's aria-valuemax type is string | number, and at runtime, the DOM stringifies numbers automatically, so this was good.
However, the TypeScript's type for HTMLElement.ariaValuemax is string. Since this code is converted by the codemod to this.el.ariaValuemax = ..., we need to be setting strings here to avoid type error.
| async function cycleThroughItemsAndAssertValue(keys: "left-right" | "up-down"): Promise<void> { | ||
| const [moveBeforeArrowKey, moveAfterArrowKey] = | ||
| keys === "left-right" ? ["ArrowLeft", "ArrowRight"] : ["ArrowUp", "ArrowDown"]; | ||
| keys === "left-right" ? (["ArrowLeft", "ArrowRight"] as const) : (["ArrowUp", "ArrowDown"] as const); |
There was a problem hiding this comment.
Lumina's typings for await element.press(moveAfterArrowKey); are more strict
| const rowPos = event["detail"].rowPosition; | ||
| const destination = event["detail"].destination; | ||
| const lastCell = event["detail"].lastCell; | ||
| calciteInternalTableRowFocusEvent(event: CustomEvent<TableRowFocusEvent>): void { |
There was a problem hiding this comment.
looks like a mistake in typing.
TableRowFocusEvent is the payload type, not event type
|
|
||
| const element = await page.find("calcite-text-area"); | ||
| element.setAttribute("max-length", 5); | ||
| element.setAttribute("max-length", "5"); |
There was a problem hiding this comment.
Stencil's E2EElement.setAttribute had type (string, any)=>void
In Lumina, it is (string, string)=>void so that it matches the HTMLElement.setAttribute type.
I want to align us closer with DOM typings so that migrating to Vitest browser mode is easier
| * @internal | ||
| */ | ||
| @Event({ cancelable: false }) calciteInternalTimePickerChange: EventEmitter<string>; | ||
| @Event({ cancelable: false }) calciteInternalTimePickerChange: EventEmitter<void>; |
There was a problem hiding this comment.
never actually included a string payload type, and no one was listening for it
| let dispatchTransitionEvent: TransitionEventDispatcher; | ||
| let onStartCallback: jest.Mock<any, any, any>; | ||
| let onEndCallback: jest.Mock<any, any, any>; | ||
| let onStartCallback: jest.Mock; |
There was a problem hiding this comment.
With this change, the type would be equivalent both in Jest and Vite.
Otherwise it was causing issues because Vite's Mock has only 2 type arguments
jcfranco
left a comment
There was a problem hiding this comment.
Other than a few comments, this is looking great! Thanks, @maxpatiiuk!
| @Listen("calciteInternalListItemGroupDefaultSlotChange") | ||
| @Listen("calciteInternalListDefaultSlotChange") | ||
| handleCalciteInternalListDefaultSlotChanges(event: CustomEvent<void>): void { | ||
| handleCalciteInternalListDefaultSlotChanges(event: CustomEvent): void { |
There was a problem hiding this comment.
Do Lumina's type set CustomEvent.detail's' type as void by default?
There was a problem hiding this comment.
yes!
To be more precise, regarding authoring events:
- default payload type in
createEvent()isundefined, rather thananylike it was in Stencil. - it is a typescript error to not provide a payload to the
.emit()function if the event has non-undefinedpayload type - the codemod will update
EventEmitter<void>toEventEmitteras needed
There was a problem hiding this comment.
edit:
Regarding listening to events, CustomEvent.detail is still any since that's coming from TypeScript.
I also see that you used CustomEvent<void> in many places, so I will revert this place to use CustomEvent<void> for consistency
| } | ||
|
|
||
| export interface InteractiveContainerProps extends JSXAttributes { | ||
| export interface InteractiveContainerProps extends JSXAttributes<HTMLDivElement> { |
There was a problem hiding this comment.
This could stay the same as we're not using any props from a particular HTML element.
Applies to XButtonProps too.
There was a problem hiding this comment.
Without the change in XButtonProps, I was getting a type error here:
The issue is that in Lumina JSX, the ref prop can be assigned either (element: HTMLButtonElement) => void or { value: HTMLButtonElement } (like a RefObject type in React).
The RefObject type is causing issues.
By default JSXAttributes interface is assuming HTMLElement type.
That means the ref prop type in the <XButton> is RefObject<HTMLElement>, which is not assignable to the RefObject<HTMLButtonElement> in the <button>.
The same issue is present in React since they also have object refs. Not an issue in Stencil since they don't have object refs, only callback refs.
The change in <InteractiveContainer> is not necessary, but I done it for consistency, and to avoid issues if someone does add a ref prop to it in the future.
There was a problem hiding this comment.
I could be misunderstanding, but it seems this change is conflating the prop types with the ref type. These can be different depending on the implementation, right?
It doesn't seem like we're using XButton's ref property, so we could alternatively drop it for the time being.
There was a problem hiding this comment.
I could be misunderstanding, but it seems this change is conflating the prop types with the ref type
JSXAttributes represents the common props type, including the ref prop.
The generic parameter you pass to JSXAttributes (eg JSXAttributes<HTMLDivElement>) dictates the type used in the ref
It doesn't seem like we're using XButton's ref property, so we could alternatively drop it for the time being.
Sounds good, I will go ahead and remove it.
There was a problem hiding this comment.
You're right. I was thinking about other use cases where we might want to provide a ref to another part of the functional component, but this would probably be better off as a separate property in the props interface.
|
Looks like GitHub action was stuck on E2E tests for 6 hours and then timed out: Triggering E2E re-run completed successfully 🤔 |
f430d28 to
6e7d00a
Compare
| } | ||
|
|
||
| return orig.call(input, init); | ||
| return orig.call(window, input, init); |
There was a problem hiding this comment.
First argument to .call is this.
Not sure why this worked before in Stencil, but this causes issues after migration.
jcfranco
left a comment
There was a problem hiding this comment.
👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤
👨🎤🤘👨🎤👨🎤👨🎤🤘👨🎤👨🎤🤘🤘👨🎤👨🎤🤘🤘🤘👨🎤👨🎤🤘🤘🤘👨🎤🤘🤘🤘🤘👨🎤🤘👨🎤
👨🎤🤘🤘👨🎤👨🎤🤘👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤👨🎤👨🎤🤘👨🎤👨🎤👨🎤👨🎤🤘👨🎤
👨🎤🤘👨🎤🤘👨🎤🤘👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤👨🎤👨🎤🤘🤘🤘👨🎤👨🎤🤘👨🎤
👨🎤🤘👨🎤👨🎤🤘🤘👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤👨🎤👨🎤🤘👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤
👨🎤🤘👨🎤👨🎤👨🎤🤘👨🎤👨🎤🤘🤘👨🎤👨🎤🤘🤘🤘👨🎤👨🎤🤘🤘🤘👨🎤🤘🤘🤘🤘👨🎤🤘👨🎤
👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤
…tracking * origin/dev: (40 commits) feat: add parcel parameter (#10384) feat(alert): apply --calcite-alert-corner-radius to internal close button (#10388) feat(dialog, panel): Add css properties for background-color (#10387) fix: remove aria-disabled from components where necessary (#10374) feat(action-group, block, panel): add `menuPlacement` and `menuFlipPlacements` properties (#10249) fix(list, filter): fix sync between list items and filtered data (#10342) feat(popover): apply component tokens to arrow (#10386) feat(list-item): add `unavailable` property (#10377) fix(segmented-control): honor appearance, layout and scale when items are added after initialization (#10368) fix(action-pad): fix horizontal action group alignment (#10359) fix(combobox): selection-mode="single-persist" correctly selects an item when items have same values (#10366) fix(input-time-zone): fix region mode labeling and value mapping (#10345) fix(dropdown): open dropdown on `ArrowDown` & `ArrowUp` keys (#10264) refactor(components): reduce post-migration TypeScript errors (#10356) refactor: do not use Host in functional components (#10352) refactor(tests): reduce TypeScript errors (#10344) feat(alert): add component tokens (#10218) fix(card): properly handle slotted elements (#10378) refactor(panel): remove duplicate tailwind class (#10379) feat(popover, action): add component tokens (#10253) ...
…estone-estimates * origin/dev: (29 commits) fix(input-time-zone): fix region mode labeling and value mapping (#10345) fix(dropdown): open dropdown on `ArrowDown` & `ArrowUp` keys (#10264) refactor(components): reduce post-migration TypeScript errors (#10356) refactor: do not use Host in functional components (#10352) refactor(tests): reduce TypeScript errors (#10344) feat(alert): add component tokens (#10218) fix(card): properly handle slotted elements (#10378) refactor(panel): remove duplicate tailwind class (#10379) feat(popover, action): add component tokens (#10253) chore(t9n): add translations (#10339) feat: add 3d building, 3d building parameter, divide, parcel, spaces, spaces parameter, square brackets x, n variable, zoning parameter (#10373) build: update browserslist db (#10370) ci: resolve husky pre-push and pre-commit errors (#10365) docs: update component READMEs (#10371) feat(text-area): add component tokens (#10343) fix(action): prefer `disabled` in favor of `aria-disabled` (#10367) docs(a11y): add reference to a11y guidance to issue template (#10372) chore(action): add new string for accessible indicator label (#10360) feat(chip): add component tokens (#10179) feat(avatar): add component tokens (#10280) ...
Run the migration script on tests.
This PR includes some small fixups that affect TypeScript typings to reduce number of TypeScript errors after the codemod.
With these changes, there are only 57 TypeScript error in the entire calcite-components package after the codemod!