Skip to content

Animated.WithAnimatedValue strips type information #28781

@cjduncana

Description

@cjduncana

Description

I'm starting to use the Animated library for React Native, and I already noticed that the compiler is not warning me of the wrong usage. Usually, style properties would alert me if I give it the incorrect value, but when I use Animated.WithAnimatedValue for components like Animated.Text, I noticed this doesn't happen anymore. For example, I see that when I use Animated.WithAnimatedValue, it turns any type T that is not a record or an array into T | Value | AnimatedInterpolation. When I use the style property color that has type string | undefined, I would expect that the new type would be string | undefined | Value | AnimatedInterpolation, instead it is any. Any suggestions?

React Native version:

System:
OS: macOS Mojave 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Memory: 126.48 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.12.0 - ~/.nvm/versions/node/v11.12.0/bin/node
Yarn: 1.17.3 - ~/.yarn/bin/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v11.12.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.8.4 - /Users/User/.rvm/rubies/ruby-2.6.5/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
API Levels: 28, 29
Build Tools: 28.0.3, 29.0.2
System Images: android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_222 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: ^16.11.0 => 16.11.0
react-native: ^0.62.2 => 0.62.2
npmGlobalPackages:
react-native: Not Found

Expected Results

TypeScript should warn the user when they give a style property the wrong type.

Snack, code example, screenshot, or link to a repository:

Example without WithAnimatedValue

Screen Shot 2020-04-28 at 10 31 10 PM

Example with WithAnimatedValue

Screen Shot 2020-04-28 at 10 32 23 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: AnimatedIssue: Author Provided ReproThis issue can be reproduced in Snack or an attached project.StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions