chore: add stronger types to several files - #28347
Merged
Merged
Conversation
This reverts commit 99fbb83.
liamdebeasi
force-pushed
the
2832-types
branch
from
October 13, 2023 13:25
88694e0 to
3a084ca
Compare
liamdebeasi
marked this pull request as ready for review
October 13, 2023 13:25
liamdebeasi
requested review from
averyrousseau and
sean-perkins
as code owners
October 13, 2023 13:25
Comment on lines
-480
to
-484
| this.animation = await menuController._createAnimation(this.type!, this); | ||
| const animation = (this.animation = await menuController._createAnimation(this.type!, this)); | ||
| if (!config.getBoolean('animated', true)) { | ||
| this.animation.duration(0); | ||
| animation.duration(0); | ||
| } | ||
| this.animation.fill('both'); |
Contributor
There was a problem hiding this comment.
Why was this change made? (Specifically moving the this reference into line 480, which makes the code a bit harder to reason about IMO.) menuController._createAnimation returns a Promise<Animation>, so I'd assume there would be no type conflicts with this.animation.
Contributor
Author
There was a problem hiding this comment.
TypeScript logged an error saying that this.animation was potentially undefined (because that's what the type definition says). Using the local variable ensures that animation is always defined due to the _createAnimation return type you noted.
Co-authored-by: Amanda Johnston <90629384+amandaejohnston@users.noreply.github.com>
averyrousseau
approved these changes
Oct 17, 2023
sean-perkins
approved these changes
Oct 23, 2023
sean-perkins
pushed a commit
that referenced
this pull request
Oct 27, 2023
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 would like to swap out usages of the any type for stronger types. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> c529bc2 - `scrollToTop` doesn't return anything, so I added the `void` return type a96971a - `animation.effect` is a type of [AnimationEffect](https://developer.mozilla.org/en-US/docs/Web/API/Animation/effect). One of the more common types of effects is a `KeyframeEffect`. However, TypeScript doesn't know which specific type of AnimationEffect we are using, so I cast `animation.effect` as KeyframeEffect where appropriate. - I also added `!` to places where we know the effect and other properties are always defined (since they run after the web animation has been constructed) - Added stronger types to the internal to/from/fromTo functions (the public facing type improvements are in #28334) fdaf550 - `getRootNode` can return multiple types of objects, so I cast it to the specific types that we work with in `isFocused`. 46a6efa - Added the "Animation" type and resolved related errors once we had stronger types a7cb9a5 - Made heavier use of the `T` generic - Once we know `node` is an Element (`nodeType === 1`) we manually cast the element as `T` 6a9d1f0 - The focus visible utility is an internal utility, but it was lacking an interface, so I added one. 90b64c2 - Removed unneeded HTMLElement casting - Added `!` since we can assume the selected elements are defined with the refresher - Added documentation as to why casting `referencEl.style` as `any` is something we need to keep. 3a084ca - Avoided the Event naming collision by using globalThis ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Note: This PR contains only type changes. Changes the required updates to the implementation of Ionic are pulled out into separate PRs and target a minor release branch to minimize risk. --------- Co-authored-by: Amanda Johnston <90629384+amandaejohnston@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue number: Internal
What is the current behavior?
As part of FW-2832, the team would like to swap out usages of the any type for stronger types.
What is the new behavior?
c529bc2
scrollToTopdoesn't return anything, so I added thevoidreturn typea96971a
animation.effectis a type of AnimationEffect. One of the more common types of effects is aKeyframeEffect. However, TypeScript doesn't know which specific type of AnimationEffect we are using, so I castanimation.effectas KeyframeEffect where appropriate.!to places where we know the effect and other properties are always defined (since they run after the web animation has been constructed)fdaf550
getRootNodecan return multiple types of objects, so I cast it to the specific types that we work with inisFocused.46a6efa
a7cb9a5
Tgenericnodeis an Element (nodeType === 1) we manually cast the element asT6a9d1f0
90b64c2
!since we can assume the selected elements are defined with the refresherreferencEl.styleasanyis something we need to keep.3a084ca
Does this introduce a breaking change?
Other information
Note: This PR contains only type changes. Changes the required updates to the implementation of Ionic are pulled out into separate PRs and target a minor release branch to minimize risk.