react-infinite-scroller icon indicating copy to clipboard operation
react-infinite-scroller copied to clipboard

Typescript definition error

Open KromDaniel opened this issue 8 years ago • 3 comments

Hey There's a mismatch between the typescript definition and the actual code

Environment: [email protected] [email protected] [email protected] @types/[email protected] [email protected]

As written at the documentation:

import InfiniteScroll from 'react-infinite-scroller';

But it returns undefined

console.log(InfiniteScroll); //undefined

Instead, when I'm trying to do

import * as InfiniteScroll from 'react-infinite-scroller';
console.log(InfiniteScroll) //Good

But then typescript compiler breaks with the error

[ts] Module '"/node_modules/@types/\react-infinite-scroller/index"' resolves to a non-module entity and cannot be imported using this construct.

How can this be fixed? thanks!

KromDaniel avatar Oct 08 '17 13:10 KromDaniel

@KromDaniel I got the same error. You need to import using require:

import InfiniteScroll  = require('react-infinite-scroller');

TypeScript does not support the import X from 'X' syntax for modules exported using export = X. See TypeScript/issues/6809

markusjohnsson avatar Oct 10 '17 09:10 markusjohnsson

@markusjohnsson Yea I did some ugly workaround, not near my code by something like

import * as InfiniteScrollTypes from "react-infinite-scroll"
const InfiniteScroll = require("react-infinite-scroller") as InfiniteScrollTypes //For the ts definitions 

KromDaniel avatar Oct 10 '17 09:10 KromDaniel

This is really a bug for the types page isn't it? https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-infinite-scroller

chrisgarber avatar Jul 05 '18 16:07 chrisgarber