Skip to content

Commit

Permalink
chore: stricter TS check for transform style
Browse files Browse the repository at this point in the history
  • Loading branch information
vonovak committed Jul 14, 2023
1 parent 06668fc commit 50cc6bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
34 changes: 19 additions & 15 deletions packages/react-native/Libraries/StyleSheet/StyleSheetTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,27 @@ interface MatrixTransform {
matrix: AnimatableNumericValue[];
}

type MaximumOneOf<T, K extends keyof T = keyof T> = K extends keyof T
? {[P in K]: T[K]} & {[P in Exclude<keyof T, K>]?: never}
: never;

export interface TransformsStyle {
transform?:
| (
| PerpectiveTransform
| RotateTransform
| RotateXTransform
| RotateYTransform
| RotateZTransform
| ScaleTransform
| ScaleXTransform
| ScaleYTransform
| TranslateXTransform
| TranslateYTransform
| SkewXTransform
| SkewYTransform
| MatrixTransform
)[]
| MaximumOneOf<
PerpectiveTransform &
RotateTransform &
RotateXTransform &
RotateYTransform &
RotateZTransform &
ScaleTransform &
ScaleXTransform &
ScaleYTransform &
TranslateXTransform &
TranslateYTransform &
SkewXTransform &
SkewYTransform &
MatrixTransform
>[]
| string
| undefined;
/**
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/types/__typetests__/animated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ function TestAnimatedAPI() {
}}
/>
;
{/* @ts-expect-error the transform object must contain only one key-value pair */}
<Animated.View style={{transform: [{scale: 1, translateX: 20}]}} />;
</View>
);
}

0 comments on commit 50cc6bf

Please sign in to comment.