-
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
base: dev
Are you sure you want to change the base?
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.
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 🤔 |
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!