Skip to content
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: fixup typescript errors #10295

Merged
merged 2 commits into from
Sep 15, 2024

Conversation

maxpatiiuk
Copy link
Member

@maxpatiiuk maxpatiiuk commented Sep 13, 2024

With the changes in this PR, after running the codemod, there are only 60 TypeScript errors in the Calcite package - those should be best fixed manually after running the codemod.
Now that error count is down to negligible level, will work on migrating tests.

@@ -279,7 +279,13 @@ export class Button
}}
disabled={childElType === "button" ? this.disabled || this.loading : null}
download={
childElType === "a" && (this.download === "" || this.download) ? this.download : null
childElType === "a"
Copy link
Member Author

@maxpatiiuk maxpatiiuk Sep 13, 2024

Choose a reason for hiding this comment

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

with this change, when this.download is true, we set the prop as "" instead.
not required for Stencil, but this is needed for Lit as download attribute is typed as string rather than string | boolean in Lumina for technical reasons (it's one few such special attributes for legacy dom reasons)

Copy link
Member

Choose a reason for hiding this comment

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

This needs to be updated or reverted. It breaks this test.

This change changes how the internal element's download attribute is applied.

before

Screenshot 2024-09-13 at 10 19 03 PM

after

Screenshot 2024-09-13 at 10 21 15 PM

@@ -43,7 +43,7 @@ import {
import { componentOnReady } from "../../utils/component";
import { SLOTS as PANEL_SLOTS } from "../panel/resources";
import { HeadingLevel } from "../functional/Heading";
import { OverlayPositioning } from "../../components";
import type { OverlayPositioning } from "../../utils/floating-ui";
Copy link
Member Author

Choose a reason for hiding this comment

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

since components.d.ts will be deleted, I'm changing this to import from the actual origin

@@ -2,7 +2,7 @@ import { FunctionalComponent, h, VNode } from "@stencil/core";
import { JSXAttributes } from "@stencil/core/internal";
import { FloatingLayout } from "../../utils/floating-ui";

interface FloatingArrowProps extends JSXAttributes {
interface FloatingArrowProps extends JSXAttributes<SVGSVGElement> {
Copy link
Member Author

Choose a reason for hiding this comment

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

this way ref callback is typed correctly, rather than as broad Element

@@ -113,7 +113,7 @@ export class Link implements InteractiveComponent, LoadableComponent {
When the 'download' property of type 'boolean | string' is set to true, the value is "".
This works around that issue for now.
*/
download={Tag === "a" && (download === "" || download) ? download : null}
download={Tag === "a" ? (download === true ? "" : download ? download : null) : null}
Copy link
Member Author

Choose a reason for hiding this comment

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

same as in button.tsx

Copy link
Member

Choose a reason for hiding this comment

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

Similar to button, this change breaks this test.

@@ -174,7 +174,7 @@ export class Link implements InteractiveComponent, LoadableComponent {
/** the rendered child element */
private childEl: HTMLAnchorElement | HTMLSpanElement;

private childElClickHandler = (event: PointerEvent): void => {
private childElClickHandler = (event: MouseEvent): void => {
Copy link
Member Author

Choose a reason for hiding this comment

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

onClick emits MouseEvent, not PointerEvent

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, this might change in the near future since Chrome and Firefox already emit pointer events, and it looks like Safari will soon (adhering to the updated spec).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the fyi.
I will revert this change and update Lumina's JSX typings.

For the future, I am looking to automate the process of keeping Lumina's JSX typings up to date with the web platform to fix the DX issue we are having with Maquette and Stencil.

@@ -268,7 +268,7 @@ export class Popover

@State() defaultMessages: PopoverMessages;

arrowEl: SVGElement;
arrowEl: SVGSVGElement;
Copy link
Member Author

Choose a reason for hiding this comment

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

the correct type for the <svg> element is SVGSVGElement.
SVGElement means "any element from the SVG namespace", just like HTMLElement means "any element from the HTML namespace"

@@ -356,7 +356,7 @@ export class Rating
}
};

private handleInputChange = (event: InputEvent) => {
private handleInputChange = (event: Event) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

onChange emits Event
onInput emits InputEvent

@@ -344,7 +344,7 @@ export class Tooltip implements FloatingUIComponent, OpenCloseComponent {
>
<FloatingArrow
floatingLayout={floatingLayout}
ref={(arrowEl: SVGElement) => (this.arrowEl = arrowEl)}
ref={(arrowEl) => (this.arrowEl = arrowEl)}
Copy link
Member Author

Choose a reason for hiding this comment

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

no longer need to type this here now that FloatingArrow ref type is typed correctly

Copy link
Member Author

Choose a reason for hiding this comment

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

these link/script tags seem needless here since they are inserted by _assets/head.ts anyway

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the cleanup!

BTW, I extracted the demo-related changes to a separate PR to keep this one focused on TS errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. I will undo those changes in this PR

@@ -1,5 +1,4 @@
import { Rule } from "eslint";
// @ts-ignore
Copy link
Member Author

Choose a reason for hiding this comment

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

PSA: do not use // @ts-ignore as it's dangerous.
Reason: once the thing that was causing the TypeScript error is fixed, the // @ts-ignore comment may remain in the code. In the future, if another TypeScript error may occur in that place, you won't see it because // @ts-ignore would hide it.

Safer alternative: // @ts-expect-error - acts just like // @ts-ignore, except, if no error was reported, TypeScript will complain of needless // @ts-expect-error (just like it was needless in this case it seems like)

Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

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

Looking great, @maxpatiiuk! 🚀

Before moving forward, can you address the button and link-related test failures?

@@ -279,7 +279,13 @@ export class Button
}}
disabled={childElType === "button" ? this.disabled || this.loading : null}
download={
childElType === "a" && (this.download === "" || this.download) ? this.download : null
childElType === "a"
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be updated or reverted. It breaks this test.

This change changes how the internal element's download attribute is applied.

before

Screenshot 2024-09-13 at 10 19 03 PM

after

Screenshot 2024-09-13 at 10 21 15 PM

@@ -113,7 +113,7 @@ export class Link implements InteractiveComponent, LoadableComponent {
When the 'download' property of type 'boolean | string' is set to true, the value is "".
This works around that issue for now.
*/
download={Tag === "a" && (download === "" || download) ? download : null}
download={Tag === "a" ? (download === true ? "" : download ? download : null) : null}
Copy link
Member

Choose a reason for hiding this comment

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

Similar to button, this change breaks this test.

@@ -174,7 +174,7 @@ export class Link implements InteractiveComponent, LoadableComponent {
/** the rendered child element */
private childEl: HTMLAnchorElement | HTMLSpanElement;

private childElClickHandler = (event: PointerEvent): void => {
private childElClickHandler = (event: MouseEvent): void => {
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, this might change in the near future since Chrome and Firefox already emit pointer events, and it looks like Safari will soon (adhering to the updated spec).

import { CSS, SUBSTITUTIONS } from "./resources";
import type { HandleMessages } from "./assets/handle/t9n";
Copy link
Member

Choose a reason for hiding this comment

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

This rearrangement causes an import/order lint error. Can you run the linter to autofix?

If you have a custom groups option for that rule, I can update ours separately to follow suit.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, interesting that pre-commit hook didn't catch this. maybe my node_modules was out of date 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the cleanup!

BTW, I extracted the demo-related changes to a separate PR to keep this one focused on TS errors.

@maxpatiiuk maxpatiiuk force-pushed the max/fixup-typescript-errors branch from 460c6e8 to 0d8576e Compare September 15, 2024 16:31
@maxpatiiuk maxpatiiuk force-pushed the max/fixup-typescript-errors branch from 0d8576e to a5a393c Compare September 15, 2024 16:49
@maxpatiiuk maxpatiiuk requested a review from jcfranco September 15, 2024 17:11
@maxpatiiuk
Copy link
Member Author

Tooltip e2e test is failing on the CI.
Doesn't seem related to the changes I done in the PR.
Locally, a different tooltip e2e test is failing (calcite-tooltip › openClose › emits with animations enable).
Unstable test, or is there something wrong with my local setup?

@jcfranco
Copy link
Member

That's an unstable test (I'll try to stabilize soon). I've triggered another run of E2E tests in the meantime.

Copy link
Member

@jcfranco jcfranco left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks, @maxpatiiuk! 🚀

@jcfranco jcfranco added the skip visual snapshots Pull requests that do not need visual regression testing. label Sep 15, 2024
@jcfranco jcfranco merged commit 6a86d80 into Esri:dev Sep 15, 2024
9 of 12 checks passed
jcfranco added a commit that referenced this pull request Sep 16, 2024
**Related Issue:** N/A

## Summary

Extracts demo page cleanup from
#10295.

Co-authored-by: Max Patiiuk <max@patii.uk>
benelan added a commit that referenced this pull request Sep 17, 2024
…estone-estimates

* origin/dev: (997 commits)
  fix: correct non-standard filled icon names (#10309)
  fix(panel): initially closed panel should be hidden (#10308)
  chore(linting): automate tracking of custom Sass functions for stylelint (#10313)
  chore: tidy up demo pages (#10314)
  build(deps): update dependency dayjs to v1.11.13 (#10283)
  build(deps): update dependency jsdom to v24.1.3 (#10298)
  build(deps): update dependency husky to v9.1.6 (#10318)
  build(deps): update angular-cli monorepo to v18.2.4 (#10317)
  docs: update component READMEs (#10316)
  refactor(stylelint): change config to module format to enable more dynamic options (#10311)
  refactor: fixup typescript errors (#10295)
  build(deps): update dependency lint-staged to v15.2.10 (#10302)
  build(deps): update dependency focus-trap to v7.6.0 (#10281)
  build(deps): update dependency husky to v9.1.5 (#10297)
  chore: release next
  feat(checkbox): add component tokens (#10221)
  revert: "chore: set default page size for E2E tests (#10219)" (#10299)
  chore(icons): ensure UI icons follow naming convention (#10292)
  chore: release next
  feat: add model-history, raster-function-history, raster function-template-history, raster-tool-history, tool-history (#10305)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip visual snapshots Pull requests that do not need visual regression testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants