react-native-shadow
react-native-shadow copied to clipboard
how to support typescript?

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';`
my way:
// @ts-ignore
import {BoxShadow} from 'react-native-shadow';
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}>>;
}
This is the definition file I created in my project ( under
src/@types/react-native-shadow.d.tsIt might not be perfect, but it work for us. Hope it can helpdeclare 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
Tnx, bro, saved me <3
My https://github.com/SrBrahma/react-native-shadow-2 have TS support :)