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

Error when using React.RefObject on Animatable.View with Typescript #218

Open
nicholasrq opened this issue Aug 30, 2018 · 3 comments
Open

Comments

@nicholasrq
Copy link

nicholasrq commented Aug 30, 2018

There's an error when you're trying to use React.createRef with Animatable.View.

This error doesn't affect functionality and everything works, but the error is really annoying.

Here's code snippet that represents the error:

image

TS compiler says this:

Type 'RefObject<AnimatableComponent<ViewProps, ViewStyle>>' is not assignable to type 'string | ((instance: ClassicComponent<AnimatableProperties<ViewStyle> & ViewProps, any> | null) => any) | RefObject<ClassicComponent<AnimatableProperties<ViewStyle> & ViewProps, any>> | ((instance: Component<...> | null) => any) | RefObject<...> | undefined'.
  Type 'RefObject<AnimatableComponent<ViewProps, ViewStyle>>' is not assignable to type 'RefObject<ClassicComponent<AnimatableProperties<ViewStyle> & ViewProps, any>>'.
    Type 'AnimatableComponent<ViewProps, ViewStyle>' is not assignable to type 'ClassicComponent<AnimatableProperties<ViewStyle> & ViewProps, any>'.
      Property 'replaceState' is missing in type 'AnimatableComponent<ViewProps, ViewStyle>'.

So my guess is that the problem is somewhere around this place in type definition:

interface AnimatableComponent<P extends {}, S extends {}> extends
    NativeMethodsMixin,
    AnimatableAnimationMethods,
    ClassicComponentClass<AnimatableProperties<S> & P> /* <-- probably, this line */ {

/* ... */

}

I've tried to play around this piece of code with no luck.

Environment:

@nicholasrq
Copy link
Author

nicholasrq commented Aug 30, 2018

as always, solution comes when you already posted an issue, ugh...

found out working type definition:

interface AnimatableComponent<P extends {}, S extends {}> extends
    NativeMethodsMixin,
    AnimatableAnimationMethods,
    Component,
    ClassicComponentClass<AnimatableProperties<S> & P> {

    refs: {
        [key: string]: Component<any, any>
    }
    /* ... */
}

basically, you need to extend from Component as well as from ClassicComponentClass, but this will give you an error that you can't extend from NativeMethodsMixin and Component simultaneously because they have different refs definition, so simple redifining of refs locally in AnimatableComponent fixes it and now everything works fine.

@baspellis
Copy link

Will this be added in an upcoming release?

baspellis pushed a commit to baspellis/react-native-animatable that referenced this issue Apr 2, 2019
@tuttodev
Copy link

tuttodev commented Apr 2, 2021

Porque no puedo ver el método animate()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants