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

how to support typescript?

Open huaiguoguo opened this issue 5 years ago • 5 comments

image

i am try yarn add @types/react-native-shadow, but is not found !

无法找到模块“react-native-shadow”的声明文件。“d:/phpstudy_pro/WWW/wuzhai/app/node_modules/react-native-shadow/index.js”隐式拥有 "any" 类型。
  Try `npm install @types/react-native-shadow` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-native-shadow';`

huaiguoguo avatar May 13 '20 02:05 huaiguoguo

my way:

// @ts-ignore
import {BoxShadow} from 'react-native-shadow';

jong-hui avatar Jun 01 '20 05:06 jong-hui

This is the definition file I created in my project ( under src/@types/react-native-shadow.d.ts It might not be perfect, but it work for us. Hope it can help

declare type RNComponent<P = {}, S = {}, SS = any> = import('react').Component<P, S, SS>;
declare type RNConstructor<T> = import('react-native').Constructor<T>;
declare type RNViewProps = import('react-native').ViewProps;
declare type RNViewStyle = import('react-native').ViewStyle;

declare module 'react-native-shadow' {
  interface BoxShadowType {
    width: number,
    height: number,
    color: string,
    border: number,
    radius: number,
    opacity: number,
    x: number,
    y: number,
    style?: RNViewStyle,
  }

  interface BorderShadowType {
    width: number,
    color: string,
    border: number,
    opacity: number,
    style?: RNViewStyle,
    side: 'top' | 'bottom' | 'left' | 'right',
    inset: boolean,
  }
  export const BoxShadow : RNConstructor<RNComponent<RNViewProps & {setting?: BoxShadowType}>>;
  export const BorderShadow : RNConstructor<RNComponent<RNViewProps & {setting?: BorderShadowType}>>;
}

ACHP avatar Aug 03 '20 13:08 ACHP

This is the definition file I created in my project ( under src/@types/react-native-shadow.d.ts It might not be perfect, but it work for us. Hope it can help

declare type RNComponent<P = {}, S = {}, SS = any> = import('react').Component<P, S, SS>;
declare type RNConstructor<T> = import('react-native').Constructor<T>;
declare type RNViewProps = import('react-native').ViewProps;
declare type RNViewStyle = import('react-native').ViewStyle;

declare module 'react-native-shadow' {
  interface BoxShadowType {
    width: number,
    height: number,
    color: string,
    border: number,
    radius: number,
    opacity: number,
    x: number,
    y: number,
    style?: RNViewStyle,
  }

  interface BorderShadowType {
    width: number,
    color: string,
    border: number,
    opacity: number,
    style?: RNViewStyle,
    side: 'top' | 'bottom' | 'left' | 'right',
    inset: boolean,
  }
  export const BoxShadow : RNConstructor<RNComponent<RNViewProps & {setting?: BoxShadowType}>>;
  export const BorderShadow : RNConstructor<RNComponent<RNViewProps & {setting?: BorderShadowType}>>;
}

very thank you

huaiguoguo avatar Sep 05 '20 10:09 huaiguoguo

Tnx, bro, saved me <3

Kasmadei avatar Oct 30 '20 18:10 Kasmadei

My https://github.com/SrBrahma/react-native-shadow-2 have TS support :)

ftzi avatar Mar 25 '21 20:03 ftzi