-
Notifications
You must be signed in to change notification settings - Fork 76
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
refactor(tests): reduce TypeScript errors #10344
Conversation
@@ -520,7 +520,7 @@ describe("calcite-chip-group", () => { | |||
expect(chipSelectSpy1).toHaveReceivedEventTimes(0); | |||
expect(chipSelectSpy2).toHaveReceivedEventTimes(0); | |||
|
|||
await chip5.setAttribute("selected", true); | |||
await chip5.toggleAttribute("selected", true); |
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.
This is a boolean attribute
Before it was being set here to selected="true"
@@ -1632,7 +1632,7 @@ describe("calcite-combobox", () => { | |||
let element: E2EElement; | |||
let comboboxItem: E2EElement; | |||
let itemNestedLi: E2EElement; | |||
let closeEvent: Promise<void>; | |||
let closeEvent: Promise<unknown>; |
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.
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)
@@ -49,7 +49,7 @@ export class ListItemGroup implements InteractiveComponent { | |||
* Fires when changes occur in the default slot, notifying parent lists of the changes. | |||
*/ | |||
@Event({ cancelable: false }) | |||
calciteInternalListItemGroupDefaultSlotChange: EventEmitter<DragEvent>; | |||
calciteInternalListItemGroupDefaultSlotChange: EventEmitter<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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -292,7 +292,7 @@ describe("calcite-segmented-control", () => { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a mistake in typing.
TableRowFocusEvent
is the payload type, not event type
@@ -150,7 +150,7 @@ describe("calcite-text-area", () => { | |||
await page.setContent("<calcite-text-area></calcite-text-area>"); | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -202,7 +202,7 @@ export class TimePicker | |||
/** | |||
* @internal | |||
*/ | |||
@Event({ cancelable: false }) calciteInternalTimePickerChange: EventEmitter<string>; | |||
@Event({ cancelable: false }) calciteInternalTimePickerChange: EventEmitter<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.
never actually included a string
payload type, and no one was listening for it
@@ -665,8 +665,8 @@ describe("dom", () => { | |||
|
|||
let element: HTMLDivElement; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.
Other than a few comments, this is looking great! Thanks, @maxpatiiuk!
@@ -304,7 +304,7 @@ export class ListItem | |||
|
|||
@Listen("calciteInternalListItemGroupDefaultSlotChange") | |||
@Listen("calciteInternalListDefaultSlotChange") | |||
handleCalciteInternalListDefaultSlotChanges(event: CustomEvent<void>): void { | |||
handleCalciteInternalListDefaultSlotChanges(event: CustomEvent): 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.
Do Lumina's type set CustomEvent.detail
's' type as void
by default?
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.
yes!
To be more precise, regarding authoring events:
- default payload type in
createEvent()
isundefined
, rather thanany
like it was in Stencil. - it is a typescript error to not provide a payload to the
.emit()
function if the event has non-undefined
payload type - the codemod will update
EventEmitter<void>
toEventEmitter
as needed
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.
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
@@ -111,7 +111,7 @@ function removeInteractionListeners(element: HTMLElement): void { | |||
); | |||
} | |||
|
|||
export interface InteractiveContainerProps extends JSXAttributes { | |||
export interface InteractiveContainerProps extends JSXAttributes<HTMLDivElement> { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the change in XButtonProps, I was getting a type error here:
calcite-design-system/packages/calcite-components/src/components/functional/XButton.tsx
Line 31 in 0b03a57
ref={ref} |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: https://github.com/Esri/calcite-design-system/actions/runs/10933000573/job/30350737756 Triggering E2E re-run completed successfully 🤔 |
f430d28
to
6e7d00a
Compare
@@ -82,7 +82,7 @@ export async function t9n(componentTestSetup: ComponentTestSetup): Promise<void> | |||
return new Response(new Blob([JSON.stringify(fakeEsMessages, null, 2)], { type: "application/json" })); | |||
} | |||
|
|||
return orig.call(input, init); | |||
return orig.call(window, input, init); |
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.
First argument to .call
is this
.
Not sure why this worked before in Stencil, but this causes issues after migration.
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.
👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤
👨🎤🤘👨🎤👨🎤👨🎤🤘👨🎤👨🎤🤘🤘👨🎤👨🎤🤘🤘🤘👨🎤👨🎤🤘🤘🤘👨🎤🤘🤘🤘🤘👨🎤🤘👨🎤
👨🎤🤘🤘👨🎤👨🎤🤘👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤👨🎤👨🎤🤘👨🎤👨🎤👨🎤👨🎤🤘👨🎤
👨🎤🤘👨🎤🤘👨🎤🤘👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤👨🎤👨🎤🤘🤘🤘👨🎤👨🎤🤘👨🎤
👨🎤🤘👨🎤👨🎤🤘🤘👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤🤘👨🎤👨🎤👨🎤👨🎤🤘👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤
👨🎤🤘👨🎤👨🎤👨🎤🤘👨🎤👨🎤🤘🤘👨🎤👨🎤🤘🤘🤘👨🎤👨🎤🤘🤘🤘👨🎤🤘🤘🤘🤘👨🎤🤘👨🎤
👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤👨🎤
…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!