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

Typescript support #114

Open
lyqht opened this issue Jul 7, 2022 · 2 comments
Open

Typescript support #114

lyqht opened this issue Jul 7, 2022 · 2 comments

Comments

@lyqht
Copy link

lyqht commented Jul 7, 2022

When i install the library in a Typescript project, I get the following error

Could not find a declaration file for module 'react-native-user-avatar'. '/Users/lyqht/project/node_modules/react-native-user-avatar/lib/module/index.js' implicitly has an 'any' type.
@tdammy92
Copy link

tdammy92 commented Sep 6, 2022

I normally get the same typescript error.

i just do //@ts-ignore

@pablolucio97
Copy link

pablolucio97 commented Feb 5, 2024

To type react-native-user-avatar you can do:

1 - Create a folder named @types inside your .src directory, and a file named userAvatar.d.ts inside it.

2 - Declare the 'react-native-user-avatar' module typing it as:

declare module 'react-native-user-avatar' {
  const content: {
    name: string;
    src?: string;
    bgColor?: string;
    bgColors?: string[];
    textColor?: string;
    size?: number;
    imageStyle?: object;
    textStyle?: object;
    style?: object;
    borderRadius?: number;
    component?: React.ComponentType;
  };
  export default content;
}

3 - Inside your tsconfig.json file, add this line to tell Typescript where to find the declaration typing file for the library:

"typeRoots": ["./node_modules/@types", "./@types"]

4 - Restart your IDE.

Now your problem should be gone. Happy coding.

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

3 participants