Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to support typescript? #50

Open
huaiguoguo opened this issue May 13, 2020 · 5 comments
Open

how to support typescript? #50

huaiguoguo opened this issue May 13, 2020 · 5 comments

Comments

@huaiguoguo
Copy link

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';`
@jong-hui
Copy link

jong-hui commented Jun 1, 2020

my way:

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

@ACHP
Copy link

ACHP commented Aug 3, 2020

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}>>;
}

@huaiguoguo
Copy link
Author

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

@Kasmadei
Copy link

Tnx, bro, saved me <3

@ftzi
Copy link

ftzi commented Mar 25, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants