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