Amplify-js: Typescript errors using 'aws-amplify-react'

Created on 18 Feb 2018  路  6Comments  路  Source: aws-amplify/amplify-js

Do you want to request a feature or report a bug?
Bug
What is the current behavior?
going through the tutorial written here : https://aws.amazon.com/blogs/mobile/announcing-aws-amplify-and-the-aws-mobile-cli/

In a Typescript project with a fresh 'create-react-app' ( with TS ) install.
I get this error on this line in App.tsx
import { withAuthenticator } from 'aws-amplify-react';

Could not find a declaration file for module 'aws-amplify-react'. '/Users/dougwood/Dev/global-care-admin/node_modules/aws-amplify-react/dist/index.js' implicitly has an 'any' type.
  Try `npm install @types/aws-amplify-react` if it exists or add a new declaration (.d.ts) file containing `declare module 'aws-amplify-react';`

Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions?

    "aws-amplify": "^0.2.6",
    "aws-amplify-react": "^0.1.32",
    "react": "^16.2.0",
documentation

Most helpful comment

@28er aws-amplify-react is written in JavaScript (unlike aws-amplify which uses TypeScript) and no one has created type definitions for it. Until someone does you need to create a file (I use aws-amplify-react.d.ts) in your project with declare module 'aws-amplify-react'; which will remove the TypeScript errors.

All 6 comments

@28er aws-amplify-react is written in JavaScript (unlike aws-amplify which uses TypeScript) and no one has created type definitions for it. Until someone does you need to create a file (I use aws-amplify-react.d.ts) in your project with declare module 'aws-amplify-react'; which will remove the TypeScript errors.

Thanks @buggy ! that'll work for now :)

@28er aws-amplify-react is written in JavaScript (unlike aws-amplify which uses TypeScript) and no one has created type definitions for it. Until someone does you need to create a file (I use aws-amplify-react.d.ts) in your project with declare module 'aws-amplify-react'; which will remove the TypeScript errors.

I'm a bit new to typescript and am trying to figure this out. I created this file, but where do I put it? Also then how do I import it?

@28er aws-amplify-react is written in JavaScript (unlike aws-amplify which uses TypeScript) and no one has created type definitions for it. Until someone does you need to create a file (I use aws-amplify-react.d.ts) in your project with declare module 'aws-amplify-react'; which will remove the TypeScript errors.

I'm a bit new to typescript and am trying to figure this out. I created this file, but where do I put it? Also then how do I import it?

I usually create a folder "types" in the "src" and create aws-amplify-react.d.ts file in there.

I'm not really sure what to do here. This boilerplate I'm using seems to be using TypeScript in .js files and complaining about the aws-amplify-react module. Is there an easy work-around? Today most of my development time has been dealing with frameworks and errors so I'm looking for an easy way out for once.

Worth noting that you will also have to add

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

to the compilerOptions field in your tsconfig.json file in order for this to work. With src/types being the route to the folder containing your custom types of course.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DougWoodCDS picture DougWoodCDS  路  3Comments

callmekatootie picture callmekatootie  路  3Comments

shinnapatthesix picture shinnapatthesix  路  3Comments

rayhaanq picture rayhaanq  路  3Comments

josoroma picture josoroma  路  3Comments