Skip to content

Commit 4fde5f0

Browse files
authored
chore: add strong types in several places (#28781)
Issue number: Internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> As part of FW-2832 the team has an initiative to remove much of the `any` usage in favor of stronger types. This will make modifications to this codebase safer as we will have access to proper type checking. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Removed several `any` usages in favor of stronger types. Note that not all of the `any` types within these files have been removed. I mainly stuck to the low hanging fruit 😄 ## Does this introduce a breaking change? - [ ] Yes - [x] No I intentionally made type changes that do not impact public APIs. Any incorrect type changes would cause our CI checks to fail. <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. -->
1 parent 4ccc150 commit 4fde5f0

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

core/src/components/menu/menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export class Menu implements ComponentInterface, MenuI {
190190
async connectedCallback() {
191191
// TODO: connectedCallback is fired in CE build
192192
// before WC is defined. This needs to be fixed in Stencil.
193-
if (typeof (customElements as any) !== 'undefined' && (customElements as any) != null) {
193+
if (typeof customElements !== 'undefined' && customElements != null) {
194194
await customElements.whenDefined('ion-menu');
195195
}
196196

core/src/components/spinner/spinner-interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface SpinnerData {
1616
y2?: number;
1717
cx?: number;
1818
cy?: number;
19-
style: any; // TODO(FW-2832): type
19+
style: { [key: string]: string | undefined };
2020
viewBox?: string;
2121
transform?: string;
2222
}

core/src/components/spinner/spinner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class Spinner implements ComponentInterface {
5454
const spinnerName = self.getName();
5555
const spinner = SPINNERS[spinnerName] ?? SPINNERS['lines'];
5656
const duration = typeof self.duration === 'number' && self.duration > 10 ? self.duration : spinner.dur;
57-
const svgs: any[] = []; // TODO(FW-2832): type
57+
const svgs: SVGElement[] = [];
5858

5959
if (spinner.circles !== undefined) {
6060
for (let i = 0; i < spinner.circles; i++) {

core/src/components/split-pane/split-pane.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const QUERY: { [key: string]: string } = {
2525
shadow: true,
2626
})
2727
export class SplitPane implements ComponentInterface {
28-
private rmL: any;
28+
private rmL?: () => void;
2929

3030
@Element() el!: HTMLElement;
3131
@State() visible = false;
@@ -65,7 +65,7 @@ export class SplitPane implements ComponentInterface {
6565
async connectedCallback() {
6666
// TODO: connectedCallback is fired in CE build
6767
// before WC is defined. This needs to be fixed in Stencil.
68-
if (typeof (customElements as any) !== 'undefined' && (customElements as any) != null) {
68+
if (typeof customElements !== 'undefined' && customElements != null) {
6969
await customElements.whenDefined('ion-split-pane');
7070
}
7171
this.styleChildren();
@@ -119,8 +119,8 @@ export class SplitPane implements ComponentInterface {
119119
};
120120

121121
const mediaList = window.matchMedia(mediaQuery);
122-
(mediaList as any).addListener(callback as any);
123-
this.rmL = () => (mediaList as any).removeListener(callback as any);
122+
mediaList.addListener(callback as any);
123+
this.rmL = () => mediaList.removeListener(callback as any);
124124
this.visible = mediaList.matches;
125125
}
126126
}

core/src/utils/helpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { Side } from '../components/menu/menu-interface';
44

55
// TODO(FW-2832): types
66

7-
declare const __zone_symbol__requestAnimationFrame: any;
8-
declare const requestAnimationFrame: any;
7+
declare const __zone_symbol__requestAnimationFrame: typeof window.requestAnimationFrame;
8+
declare const requestAnimationFrame: typeof window.requestAnimationFrame;
99

1010
export const transitionEndAsync = (el: HTMLElement | null, expectedDuration = 0) => {
1111
return new Promise((resolve) => {
@@ -23,7 +23,7 @@ export const transitionEndAsync = (el: HTMLElement | null, expectedDuration = 0)
2323
const transitionEnd = (el: HTMLElement | null, expectedDuration = 0, callback: (ev?: TransitionEvent) => void) => {
2424
let unRegTrans: (() => void) | undefined;
2525
let animationTimeout: any;
26-
const opts: any = { passive: true };
26+
const opts: AddEventListenerOptions = { passive: true };
2727
const ANIMATION_FALLBACK_TIMEOUT = 500;
2828

2929
const unregister = () => {
@@ -240,7 +240,7 @@ export const getElementRoot = (el: HTMLElement, fallback: HTMLElement = el) => {
240240
* Patched version of requestAnimationFrame that avoids ngzone
241241
* Use only when you know ngzone should not run
242242
*/
243-
export const raf = (h: any) => {
243+
export const raf = (h: FrameRequestCallback) => {
244244
if (typeof __zone_symbol__requestAnimationFrame === 'function') {
245245
return __zone_symbol__requestAnimationFrame(h);
246246
}

core/src/utils/transition/ios.transition.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const DURATION = 540;
77

88
// TODO(FW-2832): types
99

10-
const getClonedElement = (tagName: string): any => {
11-
return document.querySelector(`${tagName}.ion-cloned-element`) as any;
10+
const getClonedElement = <T extends HTMLIonBackButtonElement | HTMLIonTitleElement>(tagName: string) => {
11+
return document.querySelector<T>(`${tagName}.ion-cloned-element`);
1212
};
1313

1414
export const shadow = <T extends Element>(el: T): ShadowRoot | T => {
@@ -59,8 +59,8 @@ const createLargeTitleTransition = (
5959
rootAnimation: Animation,
6060
rtl: boolean,
6161
backDirection: boolean,
62-
enteringEl: any,
63-
leavingEl: any
62+
enteringEl: HTMLElement,
63+
leavingEl: HTMLElement | undefined
6464
) => {
6565
const enteringBackButton = getBackButton(enteringEl, backDirection);
6666
const leavingLargeTitle = getLargeTitle(leavingEl);
@@ -268,10 +268,10 @@ const animateBackButton = (
268268
const enteringBackButtonIconAnimation = createAnimation();
269269
const enteringBackButtonAnimation = createAnimation();
270270

271-
const clonedBackButtonEl = getClonedElement('ion-back-button');
271+
const clonedBackButtonEl = getClonedElement<HTMLIonBackButtonElement>('ion-back-button')!;
272272

273-
const clonedBackButtonTextEl = shadow(clonedBackButtonEl).querySelector('.button-text');
274-
const clonedBackButtonIconEl = shadow(clonedBackButtonEl).querySelector('ion-icon');
273+
const clonedBackButtonTextEl = shadow(clonedBackButtonEl).querySelector('.button-text')!;
274+
const clonedBackButtonIconEl = shadow(clonedBackButtonEl).querySelector('ion-icon')!;
275275

276276
clonedBackButtonEl.text = backButtonEl.text;
277277
clonedBackButtonEl.mode = backButtonEl.mode;
@@ -424,7 +424,7 @@ const animateLargeTitle = (
424424

425425
const KEYFRAMES = backDirection ? BACKWARDS_KEYFRAMES : FORWARDS_KEYFRAMES;
426426

427-
const clonedTitleEl = getClonedElement('ion-title');
427+
const clonedTitleEl = getClonedElement<HTMLIonTitleElement>('ion-title')!;
428428
const clonedLargeTitleAnimation = createAnimation();
429429

430430
clonedTitleEl.innerText = largeTitleEl.innerText;
@@ -468,7 +468,7 @@ export const iosTransitionAnimation = (navEl: HTMLElement, opts: TransitionOptio
468468
const CENTER = '0%';
469469
const OFF_OPACITY = 0.8;
470470

471-
const isRTL = (navEl.ownerDocument as any).dir === 'rtl';
471+
const isRTL = navEl.ownerDocument.dir === 'rtl';
472472
const OFF_RIGHT = isRTL ? '-99.5%' : '99.5%';
473473
const OFF_LEFT = isRTL ? '33%' : '-33%';
474474

0 commit comments

Comments
 (0)