mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
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. -->
This commit is contained in:
@ -7,8 +7,8 @@ const DURATION = 540;
|
||||
|
||||
// TODO(FW-2832): types
|
||||
|
||||
const getClonedElement = (tagName: string): any => {
|
||||
return document.querySelector(`${tagName}.ion-cloned-element`) as any;
|
||||
const getClonedElement = <T extends HTMLIonBackButtonElement | HTMLIonTitleElement>(tagName: string) => {
|
||||
return document.querySelector<T>(`${tagName}.ion-cloned-element`);
|
||||
};
|
||||
|
||||
export const shadow = <T extends Element>(el: T): ShadowRoot | T => {
|
||||
@ -59,8 +59,8 @@ const createLargeTitleTransition = (
|
||||
rootAnimation: Animation,
|
||||
rtl: boolean,
|
||||
backDirection: boolean,
|
||||
enteringEl: any,
|
||||
leavingEl: any
|
||||
enteringEl: HTMLElement,
|
||||
leavingEl: HTMLElement | undefined
|
||||
) => {
|
||||
const enteringBackButton = getBackButton(enteringEl, backDirection);
|
||||
const leavingLargeTitle = getLargeTitle(leavingEl);
|
||||
@ -268,10 +268,10 @@ const animateBackButton = (
|
||||
const enteringBackButtonIconAnimation = createAnimation();
|
||||
const enteringBackButtonAnimation = createAnimation();
|
||||
|
||||
const clonedBackButtonEl = getClonedElement('ion-back-button');
|
||||
const clonedBackButtonEl = getClonedElement<HTMLIonBackButtonElement>('ion-back-button')!;
|
||||
|
||||
const clonedBackButtonTextEl = shadow(clonedBackButtonEl).querySelector('.button-text');
|
||||
const clonedBackButtonIconEl = shadow(clonedBackButtonEl).querySelector('ion-icon');
|
||||
const clonedBackButtonTextEl = shadow(clonedBackButtonEl).querySelector('.button-text')!;
|
||||
const clonedBackButtonIconEl = shadow(clonedBackButtonEl).querySelector('ion-icon')!;
|
||||
|
||||
clonedBackButtonEl.text = backButtonEl.text;
|
||||
clonedBackButtonEl.mode = backButtonEl.mode;
|
||||
@ -424,7 +424,7 @@ const animateLargeTitle = (
|
||||
|
||||
const KEYFRAMES = backDirection ? BACKWARDS_KEYFRAMES : FORWARDS_KEYFRAMES;
|
||||
|
||||
const clonedTitleEl = getClonedElement('ion-title');
|
||||
const clonedTitleEl = getClonedElement<HTMLIonTitleElement>('ion-title')!;
|
||||
const clonedLargeTitleAnimation = createAnimation();
|
||||
|
||||
clonedTitleEl.innerText = largeTitleEl.innerText;
|
||||
@ -468,7 +468,7 @@ export const iosTransitionAnimation = (navEl: HTMLElement, opts: TransitionOptio
|
||||
const CENTER = '0%';
|
||||
const OFF_OPACITY = 0.8;
|
||||
|
||||
const isRTL = (navEl.ownerDocument as any).dir === 'rtl';
|
||||
const isRTL = navEl.ownerDocument.dir === 'rtl';
|
||||
const OFF_RIGHT = isRTL ? '-99.5%' : '99.5%';
|
||||
const OFF_LEFT = isRTL ? '33%' : '-33%';
|
||||
|
||||
|
Reference in New Issue
Block a user