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

[BUG] Types error with motion.create() in v11.5 #2792

Open
hoangnhan2ka3 opened this issue Sep 7, 2024 · 4 comments
Open

[BUG] Types error with motion.create() in v11.5 #2792

hoangnhan2ka3 opened this issue Sep 7, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@hoangnhan2ka3
Copy link

hoangnhan2ka3 commented Sep 7, 2024

1. Read the FAQs 👇

2. Describe the bug

Types error with motion.create() in v11.5

3. Reproduction

NaN

4. Steps to reproduce

Steps to reproduce the behavior:

  • First case:

    // src/components/ui/badge.tsx
    
    import { cva, type VariantProps } from "class-variance-authority"
    import { cn } from "@/lib/utils"
    
    const badgeVariants = cva(
        "inline-flex w-fit cursor-pointer items-center rounded-full border px-1.5 text-mini font-bold transition-colors focus:outline-none",
        {
            variants: {
                variant: {
                    default: "border-transparent bg-primary text-primary-foreground hover:bg-primary/80"
                }
            },
            defaultVariants: {
                variant: "default"
            }
        }
    )
    
    type BadgeProps = React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof badgeVariants>
    
    const Badge = ({ className, variant, ...props }: BadgeProps) => {
        return (
            <div
                className={cn(badgeVariants({ variant }), className)}
                {...props}
            />
        )
    }
    Badge.displayName = "Badge"
    
    export { Badge, badgeVariants }
    // in other file
    
    "use client"
    
    import { motion } from "framer-motion"
    import { Badge } from "@/components/ui/badge"
    
    const MotionBadge = motion.create(Badge)
    //                                ^^^^^ (Types error)

    Error:

    Argument of type '{ ({ className, variant, ...props }: BadgeProps): React.JSX.Element; displayName: string; }' is not assignable to parameter of type 'string | ForwardRefExoticComponent<BadgeProps>'.
      Property '$$typeof' is missing in type '{ ({ className, variant, ...props }: BadgeProps): React.JSX.Element; displayName: string; }' but required in type 'ForwardRefExoticComponent<BadgeProps>'.ts(2345)
    index.d.ts(636, 18): '$$typeof' is declared here.
  • Second case:

    import { Slot as ReactSlot } from "@radix-ui/react-slot"
    import { motion, type MotionProps } from "framer-motion"
    
    export interface SlotProps extends React.ComponentPropsWithoutRef<typeof ReactSlot> {
        as?: keyof React.ReactHTML | React.ComponentType<any>,
        asChild?: boolean
    }
    
    const MotionSlot = React.forwardRef<HTMLElement, SlotProps & MotionProps>(({
        as: Component = "div",
        asChild = false,
        className,
        ...props
    }, ref) => {
        const MotionComp = motion.create(getComp(asChild, Component))
    //                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ (Types error)
    
        return (
            <MotionComp ref={ref} className={className} {...props} />
        )
    })
    MotionSlot.displayName = "MotionSlot"
    
    const getComp = (asChild?: boolean, as: keyof React.ReactHTML | React.ComponentType<any> = "div") => {
        return asChild ? ReactSlot : as
    }
    
    export { MotionSlot }

    Error:

    Argument of type 'ForwardRefExoticComponent<SlotProps & RefAttributes<HTMLElement>> | keyof ReactHTML | ComponentType<...>' is not assignable to parameter of type 'string | ForwardRefExoticComponent<SlotProps & RefAttributes<HTMLElement>>'.
      Type 'ComponentClass<any, any>' is not assignable to type 'string | ForwardRefExoticComponent<SlotProps & RefAttributes<HTMLElement>>'.
        Property '$$typeof' is missing in type 'ComponentClass<any, any>' but required in type 'ForwardRefExoticComponent<SlotProps & RefAttributes<HTMLElement>>'.ts(2345)
    index.d.ts(636, 18): '$$typeof' is declared here.

5. Expected behavior

No types error like in v11.3.31.

6. Video or screenshots

NaN

7. Environment details

If applicable, let us know which OS, browser, browser version etc you're using.

Software Name(s) Version
Framer Motion framer-motion 12.0.0-alpha.1
NextJs next 15.0.0-canary.144
React react 19.0.0-rc-a03254bc-20240905
Typescript typescript 5.5.4
Node n/a 20.11.1
Package Manager pnpm 9.9.0
Operating System Windows 11 Insider Preview 10.0.26120.751

image

@hoangnhan2ka3 hoangnhan2ka3 added the bug Something isn't working label Sep 7, 2024
@Fyz1408
Copy link

Fyz1408 commented Sep 17, 2024

I'm getting the exact same error would love to see a fix

@rafaelklaessen
Copy link

Would be great if this could be looked at!

@ygorluiz
Copy link

As a temporary solution until the issue is resolved, we can employ the Slot component provided by Radix UI

@binaryartifex
Copy link

yep, this has just brought everything to a standstill. trying to pass any react-aria components to motion wrapper...

import {
  Modal,
  ModalOverlay,
} from "react-aria-components";
import { motion } from "framer-motion";

const MotionModalOverlay = motion(ModalOverlay);
const MotionModal = motion(Modal);

if i hover over the ModalOverlay error i get

Argument of type '(props: ModalOverlayProps & RefAttributes<HTMLDivElement>) => ReactElement<any, string | JSXElementConstructor<any>> | null' is not assignable to parameter of type 'string | ForwardRefExoticComponent<ModalOverlayProps & RefAttributes<HTMLDivElement>>'.
  Property '$$typeof' is missing in type '(props: ModalOverlayProps & RefAttributes<HTMLDivElement>) => ReactElement<any, string | JSXElementConstructor<any>> | null' but required in type 'ForwardRefExoticComponent<ModalOverlayProps & RefAttributes<HTMLDivElement>>'.ts(2345)
index.d.ts(636, 18): '$$typeof' is declared here.
  • "framer-motion": "^11.8.0"
  • "react-aria-components": "1.3.3"
  • "react": "18.3.1"
  • "@types/react": "18.3.9"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants