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

TypeScript 5 #2587

Merged
merged 23 commits into from
Apr 12, 2024
Merged

TypeScript 5 #2587

merged 23 commits into from
Apr 12, 2024

Conversation

mattgperry
Copy link
Collaborator

@mattgperry mattgperry commented Mar 22, 2024

Fixes #2592

Copy link
Contributor

@Coobaha Coobaha left a comment

Choose a reason for hiding this comment

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

👏 Mostly did a quick check and pushed minor fixes while reviewing 👼

There are some unsound places due to typecasting. Fixing them would require converting many parts to be more static and may not be worth it as it could require significant changes and new bugs.

  • I noticed that the dev command logs errors.
image
  • bumped the CI base image to upgrade the Node.js version to v20 so it works with the new syntax.

  • bumped jest/eslint deps related to TS as they were broken (ts-jest supports ts5.4, and at least in my editor eslint was not working)

  • I think tests and editor are using different config as I had no errors in the editor,r but tests were showing tsc errors

fallbackAnimation[key] =
fallbackTarget === undefined ? null : fallbackTarget
// @ts-expect-error - @mattgperry to figure if we should do something here
fallbackAnimation[key] = fallbackTarget ?? null
Copy link
Contributor

Choose a reason for hiding this comment

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

@mattgperry Noticed here a valid ts error, as type of fallbackAnimation[key] is number | string and it assigns null

image

@Coobaha Coobaha self-requested a review March 27, 2024 15:01
expect(ease![0]).toEqual("linear")
expect(ease![1]).toEqual("linear")
expect(typeof ease![2]).toEqual("function")
expect((ease as Easing[])[0]).toEqual("linear")

Choose a reason for hiding this comment

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

@mattgperry
There is degradation in type-checking.
It’s safer to use non-null assertion than as.
https://www.reddit.com/r/typescript/comments/11rqtn3/is_as_any_better_than_to_assert_nonnullishness/

@@ -43,12 +43,14 @@ function useVisualProps(props: ThreeMotionProps & MeshProps) {
const visualProps: ThreeMotionProps & MeshProps = {}

for (const key in props) {
const prop = props[key]
const prop = props[key as keyof typeof props]
Copy link

@o-alexandrov o-alexandrov Mar 28, 2024

Choose a reason for hiding this comment

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

@mattgperry how about depending on:

  • function’s return type (it handles cases when type-checking of Framer Motion is done outside of this repo, i.e by users-devs)
  • and global per-repo type override for loops, so the key is auto-inferred from the array/object (it handles cases when type-checking is performed within the repo)

It would ensure cases like this don’t need manual as override, removing possibilities of human errors.

If you still want to manually define key’s type, then you should do it once before the for loop.

@mattgperry mattgperry added the automerge Land this PR label Apr 12, 2024
@mergetron mergetron bot merged commit af26453 into main Apr 12, 2024
1 check passed
@mergetron mergetron bot deleted the feature/ts5 branch April 12, 2024 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Land this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] framer-motion is incompatible with TypeScript v5.4
3 participants