digital-flowers / react-animated-css

React component to show or hide elements with animations
https://digital-flowers.github.io/react-animated-css.html
232 stars 36 forks source link

error if i used typescript #48

Open RoniJackVituli opened 1 year ago

RoniJackVituli commented 1 year ago

No overload matches this call. Overload 1 of 2, '(props: AnimatedProps | Readonly): Animated', gave the following error. Type '{ children: Element; animationIn: "bounceInLeft"; animationOut: "fadeOut"; isVisible: true; Read: true; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'. Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'. Overload 2 of 2, '(props: AnimatedProps, context: any): Animated', gave the following error. Type '{ children: Element; animationIn: "bounceInLeft"; animationOut: "fadeOut"; isVisible: true; Read: true; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'. Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly'.

lkwr commented 1 year ago

Should be fixed if #47 get merged.

But you can temporary create the type your own:

Create a types.d.ts file in your source folder and put in the following:

// types.d.ts
import { ReactNode } from "react";

declare module "react-animated-css" {
  export interface AnimatedProps {
    children: ReactNode;
  }
}

And it should works!

RoniJackVituli commented 1 year ago

Thank you! It's work. Maybe to add this solution to the readme? Because a lot of people work with typescript. 😀

gre-dev commented 1 year ago

Should be fixed if #47 get merged.

But you can temporary create the type your own:

Create a types.d.ts file in your source folder and put in the following:

// types.d.ts
import { ReactNode } from "react";

declare module "react-animated-css" {
  export interface AnimatedProps {
    children: ReactNode;
  }
}

And it should works!

If doesn't work..

After creating the types.d.ts file in your root directory and putting the code mentioned by @lkwr, just make sure that your tsconfig.json contains the created file in the files property:

Sample 👇🏻:

{
  "files": [
    "./types.d.ts"
  ],
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src",
    "product.json"
  ]
}
Drakenwolf commented 1 year ago

I have the same problem, i have a workaround but the Animated component must be able to receive childrens.