react-scroll-to-bottom icon indicating copy to clipboard operation
react-scroll-to-bottom copied to clipboard

Try npm install @types/react-scroll-to-bottom

Open h4liss0n opened this issue 4 years ago • 5 comments

Hi flow!I I have a problem! How to use this component in the application with React and typescript?  I install and create simple chat app when run command npm i react-scroll-to-bottom  result OK, no problem. But when I run command npm start result this problem\error:

Could not find a declaration file for module 'react-scroll-to-bottom'. './node_modules/react-scroll-to-bottom/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/react-scroll-to-bottom` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-scroll-to-bottom';`  TS7016

h4liss0n avatar Apr 25 '21 14:04 h4liss0n

We are not a TypeScript component, thus, we are not publishing declarations (a.k.a. typings, or .d.ts).

Can your application relax to support React components written in JavaScript?

compulim avatar May 13 '21 19:05 compulim

@compulim You can publish typings even without writing your component in TypeScript. The way you do this is simple - add a .d.ts file with the type definitions, and then point to this file in your package.json using the types property. You'll be helping support a very large percentage of your consumers by doing this.

I've created a pull request that should do the trick: https://github.com/compulim/react-scroll-to-bottom/pull/96

justinbhopper avatar May 16 '21 15:05 justinbhopper

We are not a TypeScript component, thus, we are not publishing declarations (a.k.a. typings, or .d.ts).

Can your application relax to support React components written in JavaScript?

I do really wireting with the javascript/ typescript component of react application, I can relax typescript rules. Thank you very much all

h4liss0n avatar May 18 '21 13:05 h4liss0n

@compulim You can publish typings even without writing your component in TypeScript. The way you do this is simple - add a .d.ts file with the type definitions, and then point to this file in your package.json using the types property. You'll be helping support a very large percentage of your consumers by doing this.

I've created a pull request that should do the trick: #96

I'm feel truly, this change is very very helpful to us!

h4liss0n avatar May 18 '21 13:05 h4liss0n

While we are waiting for the PR #96 to be resolved. You can add this to your code to satisfy the great work @justinbhopper did to a .d.ts file.

declare module 'react-scroll-to-bottom' {
  import * as React from 'react';

  interface ReactScrollToBottomProps {
    checkInterval?: number;
    className?: string;
    debounce?: number;
    followButtonClassName?: string;
    mode?: string;
    scrollViewClassName?: string;
    children: React.ReactNode;
    debug?: boolean;
  }

  interface ScrollOptions {
    behavior: ScrollBehavior;
  }

  interface FunctionContextProps {
    scrollTo: (scrollTo: number, options: ScrollOptions) => void;
    scrollToBottom: (options: ScrollOptions) => void;
    scrollToEnd: (options: ScrollOptions) => void;
    scrollToStart: (options: ScrollOptions) => void;
    scrollToTop: (options: ScrollOptions) => void;
  }

  const FunctionContext: React.Context<FunctionContextProps>;

  export default class ScrollToBottom extends React.PureComponent<ReactScrollToBottomProps> {}
}

mrbernnz avatar Apr 12 '22 13:04 mrbernnz