TypeScript - Issue with transform (and other) props (1.8.0)
See original GitHub issueHello.
I’ve just upgraded from 1.4.0 and I keep getting lots of TypeScript compilation errors. So for example following code:
export type AnimatedNumber = Animated.Adaptable<number>; // or Animated.Value<number>
export type AnimatedPosition = {
x: AnimatedNumber;
y: AnimatedNumber;
};
type Props = {
initialPosition: AnimatedPosition;
};
const GameInteractableFlag = ({initialPosition}: Props) => {
return (
<Animated.View
style={[
styles.imageFlag,
{
transform: [ // these lines
{translateX: initialPosition.x}, // and this
{translateY: initialPosition.y}, // and this
], // and this
},
]}>
<FastImage source={images.flag} imageStyle={styles.imageFlag} />
</Animated.View>
);
};
is showing following error:
No overload matches this call.
Overload 1 of 2, '(props: Readonly<AnimateProps<ViewStyle, ViewProps>>): View', gave the following error.
Type '{ transform: ({ translateX: Animated.Adaptable<number>; } | { translateY: Animated.Adaptable<number>; })[]; }' is not assignable to type 'false | AnimateStyle<ViewStyle> | RegisteredStyle<AnimateStyle<ViewStyle>> | RecursiveArray<false | AnimateStyle<ViewStyle> | RegisteredStyle<...> | null | undefined> | readonly (false | ... 3 more ... | undefined)[] | null | undefined'.
Types of property 'transform' are incompatible.
Type '({ translateX: Adaptable<number>; } | { translateY: Adaptable<number>; })[]' is not assignable to type 'AnimatedTransform'.
Type '{ translateX: Adaptable<number>; } | { translateY: Adaptable<number>; }' is not assignable to type 'never'.
Type '{ translateX: Animated.Adaptable<number>; }' is not assignable to type 'never'.
Overload 2 of 2, '(props: AnimateProps<ViewStyle, ViewProps>, context?: any): View', gave the following error.
Type '{ transform: ({ translateX: Animated.Adaptable<number>; } | { translateY: Animated.Adaptable<number>; })[]; }' is not assignable to type 'false | AnimateStyle<ViewStyle> | RegisteredStyle<AnimateStyle<ViewStyle>> | RecursiveArray<false | AnimateStyle<ViewStyle> | RegisteredStyle<...> | null | undefined> | readonly (false | ... 3 more ... | undefined)[] | null | undefined'.
Types of property 'transform' are incompatible.
Type '({ translateX: Adaptable<number>; } | { translateY: Adaptable<number>; })[]' is not assignable to type 'AnimatedTransform'.
Type '{ translateX: Adaptable<number>; } | { translateY: Adaptable<number>; }' is not assignable to type 'never'.
Type '{ translateX: Animated.Adaptable<number>; }' is not assignable to type 'never'.ts(2769)
and also for example animated SVG path:
import {Path} from 'react-native-svg';
const AnimatedPath = Animated.createAnimatedComponent<typeof Path>(Path);
...
<AnimatedPath
d={d}
strokeDasharray={length}
strokeDashoffset={interpolate(runner, { // these lines below
inputRange: [0, 1],
outputRange: [length, 1],
extrapolate: Extrapolate.CLAMP,
})}
opacity={interpolate(runner, {. // and these lines below
inputRange: [0, 0.25, 1],
outputRange: [0, 0.8, 1],
extrapolate: Extrapolate.CLAMP,
})}
fill={fill}
stroke={stroke}
strokeWidth={strokeWidth}
/>
are showing following error message:
Type 'AnimatedNode<number>' is not assignable to type 'string | number | undefined'.
Type 'AnimatedNode<number>' is not assignable to type 'number'.ts(2322)
index.d.ts(136, 3): The expected type comes from property 'strokeDashoffset' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<PathProps, any, any>> & Readonly<PathProps> & Readonly<...>'
Can anyone help me to make this work? Thank you so much!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:20
- Comments:38 (13 by maintainers)
Top Results From Across the Web
Documentation - JSX - TypeScript
JSX is an embeddable XML-like syntax. It is meant to be transformed into valid JavaScript, though the semantics of that transformation are ...
Read more >Unsure what type my prop is in react native typescript
The transform property of your style object needs to be an array where each object is one of these supported transform types.
Read more >CoffeeScript
This allows different versions of CoffeeScript to be installed globally and locally. If you plan to use the --transpile option (see Transpilation) you...
Read more >Changelog – react-day-picker docs
Mostly an update for TypeScript users, few minor fixes, and two new minor props to the input component. DayPicker. Fixed: left/right keyboard navigation...
Read more >AngularJS to Angular concepts: Quick reference
Notice the other syntax differences: ... Angular pipes provide formatting and transformation for data in the template, like AngularJS filters.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Able to reproduce, issue appears in strict mode
the patches do not seem to fix all of the errors in my project:
all remaining errors are related to rotation transforms