question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript declaration

See original GitHub issue

Nice component William,

I program using typescript, then I had to make my own “d.ts” script for your components.

Here it is, though pretty simple, hope it’s usefull:

## reactNativeExpoImageCache.d.ts

declare module 'react-native-expo-image-cache' {
  import React from "react"
  import { ImageStyle, ViewStyle } from "react-native"

  export function Image(
    style: ViewStyle & ImageStyle,
    preview: string,
    uri: string
  ): React.Component
  
  type Listener = (uri: string) => any

  export class CacheManager {
    static listeners: { [uri: string]: Listener[] }
    static cache: (uri: string, listener: Listener) => Promise<void>
  }

}

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Simmetopiacommented, Dec 4, 2018

as of 12/4/2018 these typings is 1 to 1 to your own flow documentation.

declare module 'react-native-expo-image-cache' {
  import React from 'react';
  import { Animated, ImageStyle, ImageSourcePropType } from 'react-native';

  export interface DownloadOptions = {
    md5?: boolean;
    headers?: { [string]: string };
  };

  export interface ImageProps {
    style?: ImageStyle;
    defaultSource?: ImageSourcePropType;
    preview?: ImageSourcePropType;
    options?: DownloadOptions;
    uri: string;
    transitionDuration?: number;
    tint?: 'dark' | 'light';
  }

  interface ImageState {
    uri: string;
    intensity: Animated.Value;
  }

  export class Image extends React.Component<ImageProps, ImageState> {}

  type Listener = (uri: string) => void;

  export class CacheManager {
    static async cache(uri: string, listener: Listener): Promise<void>;
  }
}
0reactions
jhalborgcommented, Nov 29, 2018

@wcandillon - It would be much better if you can include it in the repo and maintain it with updates. @types packages often lag behind on updates for smaller libraries such as this one

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Introduction - TypeScript
The Declaration Files section is designed to teach you how to write a high-quality TypeScript Declaration File. We need to assume basic familiarity...
Read more >
A quick introduction to “Type Declaration” files and adding ...
We can write our own TypeScript Declaration files or have them produced from the compilation of TypeScript files ( .ts ) by setting ......
Read more >
TypeScript — Type Declaration Files | by Makesh Kumar
Type declaration files are the files with d.ts extension, where types were declared via interface or type . These declaration files have no...
Read more >
Declaration Files | The TypeScript Workshop
The entire reason why we use TypeScript in the first place is to give our applications a specified structure based on types. Declaration...
Read more >
Declaration Files - TypeScript Deep Dive - Gitbook
Declaration Files · You can tell TypeScript that you are trying to describe code that exists elsewhere (e.g. written in JavaScript/CoffeeScript/The runtime ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found