From f7ba6e840d343675432dfd7886d112977d1531a0 Mon Sep 17 00:00:00 2001 From: Shinpei Date: Sat, 1 Feb 2020 01:28:41 +0900 Subject: [PATCH] [@types/react-native] Fix: Animated Components are always any type (#41939) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: Animated Components are always any type * Update index.d.ts * Update types/react-native/index.d.ts Co-Authored-By: Eloy Durán * Update index.d.ts * Update index.d.ts * Update index.d.ts * Update index.d.ts * Fix: Ts Error * Test: Animated.Image missing source prop * Type: Animated Value Props * Update index.d.ts * Update index.d.ts * Update index.d.ts * Type: Bump Minimum TypeScript Version to 3.7 * Update index.d.ts * Update index.d.ts * Update index.d.ts * Fix: no-unnecessary-qualifier Co-authored-by: Eloy Durán --- types/react-native/index.d.ts | 35 +++++++++++++++++++++------- types/react-native/test/animated.tsx | 2 +- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index e655d2b922..018f009fcc 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -3994,7 +3994,7 @@ export interface FlatListProps extends VirtualizedListProps { removeClippedSubviews?: boolean; } -export class FlatList extends React.Component> { +export class FlatList extends React.Component> { /** * Scrolls to the end of the content. May be janky without `getItemLayout` prop. */ @@ -4227,7 +4227,7 @@ export interface SectionListScrollParams { viewPosition?: number; } -export class SectionList extends React.Component> { +export class SectionList extends React.Component> { /** * Scrolls to the item at the specified sectionIndex and itemIndex (within the section) * positioned in the viewable area such that viewPosition 0 places it at the top @@ -8472,21 +8472,38 @@ export namespace Animated { */ export function event(argMapping: Array, config?: EventConfig): (...args: any[]) => void; + export type ComponentProps = T extends React.ComponentType | React.Component ? P : never; + + export interface WithAnimatedValue + extends ThisType< + T extends object + ? { [K in keyof T]?: WithAnimatedValue } + : T extends (infer P)[] + ? WithAnimatedValue

[] + : T | Value | AnimatedInterpolation + > {} + + export type AnimatedProps = { [key in keyof T]: WithAnimatedValue }; + + export interface AnimatedComponent> | React.Component>> extends React.FC>> { + getNode: () => T; + } + /** * Make any React component Animatable. Used to create `Animated.View`, etc. */ - export function createAnimatedComponent(component: any): any; + export function createAnimatedComponent> | React.Component>>(component: T): AnimatedComponent> ? InstanceType : T>; /** * Animated variants of the basic native views. Accepts Animated.Value for * props and style. */ - export const View: any; - export const Image: any; - export const Text: any; - export const ScrollView: any; - export const FlatList: any; - export const SectionList: any; + export const View: AnimatedComponent; + export const Image: AnimatedComponent; + export const Text: AnimatedComponent; + export const ScrollView: AnimatedComponent; + export const FlatList: AnimatedComponent; + export const SectionList: AnimatedComponent; } // tslint:disable-next-line:interface-name diff --git a/types/react-native/test/animated.tsx b/types/react-native/test/animated.tsx index a742040caf..6a7450f7c3 100644 --- a/types/react-native/test/animated.tsx +++ b/types/react-native/test/animated.tsx @@ -84,7 +84,7 @@ function TestAnimatedAPI() { ]} /> - + ); }