react-native-actionsheet icon indicating copy to clipboard operation
react-native-actionsheet copied to clipboard

how to use in TypeScript

Open haoxiaoxin opened this issue 7 years ago • 8 comments

haoxiaoxin avatar May 28 '18 01:05 haoxiaoxin

You can use any un-typed module in typescript by either doing

const ActionSheet = require("react-native-actionsheet").default;

or

// @ts-ignore
import ActionSheet from "react-native-actionsheet";

I prefer require as it makes it more obvious when I'm bringing an unsafe object in.

david-cako avatar Jun 21 '18 22:06 david-cako

Declare this definition file on your own project

declare module 'react-native-actionsheet' {
  import { Component } from 'react';

  interface Props {
    options: (string | React.ReactNode)[];
    onPress: (index: number) => void;
    title?: string;
    message?: string;
    tintColor?: string;
    cancelButtonIndex?: number;
    destructiveButtonIndex?: number;
    styles?: object;
  }

  class ActionSheet extends Component<Props> {
    public show: () => void;
  }

  export default ActionSheet;
}

JWWon avatar Apr 11 '19 06:04 JWWon

Is there any "how to" for using this library with typescript? (react-native newbie)

this.ActionSheet.show() where ActionSheet is not found!

Sub-Zero-1 avatar Nov 13 '19 13:11 Sub-Zero-1

@JWWon TS complains the module can not be augmented:

Invalid module name in augmentation. Module 'react-native-actionsheet' resolves to an untyped module at 'c:/projects/app/node_modules/react-native-actionsheet/lib/index.js', which cannot be augmented.ts(2665)

pke avatar Jun 03 '20 15:06 pke

@JWWon your typings are missing the ref prop. I tried it with

ref: RefObject<Component<Props>>;

but it compains when using useRef<ActionSheet> as a ref. image

pke avatar Jun 03 '20 22:06 pke

anybody how to use this with typescript pls help

TruongNguyen95 avatar Sep 11 '20 07:09 TruongNguyen95

Please help

blaze-nitd avatar May 06 '21 18:05 blaze-nitd

yarn add @types/react-native-actionsheet

cletter7 avatar Dec 05 '21 14:12 cletter7