Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use AWS Amplify in React Native with Typescript Project?

I'm trying to add Amplify Authentication in my react native project which uses typescript. There is a package given in amplify documentation 'aws-amplify-react-native' which is used as a middleware to authenticate our application. But this package is only supported in projects which are based on javascript. For Typescript it shows an error like

Could not find a declaration file for module 'aws-amplify-react-native'.
Try `npm install @types/aws-amplify-react-native` if it exists or add a new declaration (.d.ts) file containing `declare module 'aws-amplify-react-native';`

There is no package available like '@types/aws-amplify-react-native'

So anyone can help me out of this?

like image 326
radhika thakkar Avatar asked Jun 22 '20 10:06

radhika thakkar


People also ask

What languages does AWS amplify support?

Q: What languages and platforms do Amplify libraries support? Amplify libraries support iOS, Android, Web, Flutter, and React Native apps. For Web apps, there is deep integration with React, Ionic, Angular, and Vue. js.

How do you deploy react app on AWS amplify?

Deploy and Host a React App (10 minutes): Create a React app and deploy and host through AWS Amplify. Initialize a Local App (5 minutes): Initialize a local app using AWS Amplify. Add Authentication (10 minutes): Add auth to your application. Add a GraphQL API and Database (15 minutes): Create a GraphQL API.


2 Answers

Unfortunately there are no defined types at the time of this answer. However, you can invoke @ts-ignore like so

// @ts-ignore
import Amplify, { Auth } from 'aws-amplify';
// @ts-ignore
import awsconfig from './aws-exports';
// @ts-ignore
import { withAuthenticator } from 'aws-amplify-react-native'

Amplify.configure(awsconfig);
like image 158
Will Jefferies Avatar answered Dec 27 '22 00:12

Will Jefferies


There are no official TypeScript (TS) types available for aws-amplify-react-native at the moment. To suppress the TypeScript warning, you need to define your own TS declaration file (*.d.ts).

To get approximate typings, you can copy this file into your project. These are typings written by the GitHub user dantasfiles. Bear in mind that they are not exact and could be specified more precisely.

like image 36
NiFi Avatar answered Dec 27 '22 01:12

NiFi