From 32f58bbeea8f32e3fa6d3d7b1e6adec8cbfbfe2d Mon Sep 17 00:00:00 2001 From: Valentin Tolochko <33843864+vtolochk@users.noreply.github.com> Date: Mon, 6 Jan 2020 12:23:40 +0200 Subject: [PATCH] [react-native] fixes StyleSheet.flatten use caused by StyleSheet.compose definition (#41408) --- types/react-native/index.d.ts | 6 +++--- types/react-native/test/index.tsx | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 209ddff4a5..9f4fd748b5 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -1963,10 +1963,10 @@ export interface ViewPropsAndroid { } type Falsy = undefined | null | false; -interface RecursiveArray extends Array> {} +interface RecursiveArray extends Array | RecursiveArray> {} /** Keep a brand of 'T' so that calls to `StyleSheet.flatten` can take `RegisteredStyle` and return `T`. */ type RegisteredStyle = number & { __registeredStyleBrand: T }; -export type StyleProp = T | RegisteredStyle | ReadonlyArray | RecursiveArray | Falsy> | Falsy; +export type StyleProp = T | RegisteredStyle | RecursiveArray | Falsy> | Falsy; /** * @see https://facebook.github.io/react-native/docs/accessibility.html#accessibility-properties @@ -5136,7 +5136,7 @@ export namespace StyleSheet { * an array, saving allocations and maintaining reference equality for * PureComponent checks. */ - export function compose(style1: StyleProp, style2: StyleProp): StyleProp; + export function compose(style1: StyleProp | Array>, style2: StyleProp | Array>): StyleProp; /** * WARNING: EXPERIMENTAL. Breaking changes will probably happen a lot and will diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 599093c9d3..3b388a9350 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -187,6 +187,11 @@ const textProperty = StyleSheet.flatten(textStyle).fontSize; const imageProperty = StyleSheet.flatten(imageStyle).resizeMode; const fontVariantProperty = StyleSheet.flatten(fontVariantStyle).fontVariant; +// correct use of the StyleSheet.flatten +const styleArray: StyleProp[] = []; +const flattenStyle = StyleSheet.flatten(styleArray); +const { top } = flattenStyle; + const s = StyleSheet.create({ shouldWork: { fontWeight: "900", // if we comment this line, errors gone