mifi / react-lottie-player

Fully declarative React Lottie player
MIT License
495 stars 52 forks source link

export LottieProps #46

Closed PavelZhuravlev closed 2 years ago

PavelZhuravlev commented 3 years ago

Hi, Thank you for the great component!

I have a question, Is there any way I can import LottieProps type to my project?

mifi commented 2 years ago

Hi! I'm not a master of TS, but if someone wants to fix it, PR is welcome.

milesrichardson commented 2 years ago

until this is fixed you can hack around it with type inference like this:

import Lottie from "react-lottie-player";

// react-lottie-player doesn't export LottieProps
// https://stackoverflow.com/a/50924506/3793499
type TypeWithGeneric<T> = React.FC<T>;
type extractGeneric<Type> = Type extends TypeWithGeneric<infer X> ? X : any;
type LottiePropsIncludingNativeHTMLProps = extractGeneric<typeof Lottie>;
type LottieProps = Omit<
  LottiePropsIncludingNativeHTMLProps,
  | keyof React.ClassAttributes<HTMLDivElement>
  | keyof React.HTMLAttributes<HTMLDivElement>
>;
export interface IAnimationProps extends LottieProps {
  play?: boolean;
}