0

I am trying to use a 'scroll to top' component:

import ScrollUpButton from 'react-scroll-up-button';

It seems that because I am using Typescript, it doesn't accept this import for some reason. I get an unusual error, but no idea what to do with it (the first recommendation for Typing does not work):

Could not find a declaration file for module 'react-scroll-up-button'. '/../react-scroll-up-button/dist/react-scroll-up-button.js' implicitly has an 'any' type.
  Try `npm install @types/react-scroll-up-button` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-scroll-up-button';`
2
  • Does this answer your question? stackoverflow.com/questions/41292559/… Commented Jul 23, 2020 at 13:15
  • Changing from import to require generates a completely different type of error with the core (albeit, no longer with this library): Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Commented Jul 23, 2020 at 13:19

1 Answer 1

1

You could create a typedef file(react-scroll-up-button.d.ts) inside the folder where you have your .ts file with the next content:

declare module 'foo';

This will create a basic type definition, so your ScrollUpButton will be of type any. You could extend the type def if you want, but this should be enough to clean up the error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.