From cdc4f7e325af0d49010925eb65dac4882d128ed4 Mon Sep 17 00:00:00 2001 From: George Cheng Date: Fri, 24 May 2019 16:50:42 +0800 Subject: [PATCH] react-native: Fix the return type of queryCache (#35681) * Fix the return type of queryCache Ref: https://github.com/facebook/react-native/pull/23602 * fix * lint * Add queryCache test to Image --- types/react-native/index.d.ts | 4 ++-- types/react-native/test/index.tsx | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 2c2bd1e21d..879fad3047 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -3992,7 +3992,7 @@ export class Image extends ImageBase { static getSize(uri: string, success: (width: number, height: number) => void, failure: (error: any) => void): any; static prefetch(url: string): any; static abortPrefetch?(requestId: number): void; - static queryCache?(urls: string[]): Promise>; + static queryCache?(urls: string[]): Promise<{[url: string]: "memory" | "disk" | "disk/memory"}>; /** * @see https://facebook.github.io/react-native/docs/image.html#resolveassetsource @@ -4013,7 +4013,7 @@ export class ImageBackground extends ImageBackgroundBase { getSize(uri: string, success: (width: number, height: number) => void, failure: (error: any) => void): any; prefetch(url: string): any; abortPrefetch?(requestId: number): void; - queryCache?(urls: string[]): Promise>; + queryCache?(urls: string[]): Promise<{[url: string]: "memory" | "disk" | "disk/memory"}>; } export interface ViewToken { diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index a1ca78f84b..b9e9912e27 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -701,10 +701,17 @@ class WebViewTest extends React.Component { export class ImageTest extends React.Component { componentDidMount(): void { - const image: ImageResolvedAssetSource = Image.resolveAssetSource({ - uri: "https://seeklogo.com/images/T/typescript-logo-B29A3F462D-seeklogo.com.png", - }); + const uri = "https://seeklogo.com/images/T/typescript-logo-B29A3F462D-seeklogo.com.png"; + const image: ImageResolvedAssetSource = Image.resolveAssetSource({ uri }); console.log(image.width, image.height, image.scale, image.uri); + + Image.queryCache([uri]).then(({ [uri]: status }) => { + if (status === undefined) { + console.log("Image is not in cache"); + } else { + console.log(`Image is in ${status} cache`); + } + }) } handleOnLoad = (e: NativeSyntheticEvent) => {