skip to Main Content

I installed a package called "js-linq" (https://github.com/battousai999/js-linq) via npm install js-linq and it appeared to install correctly. This is explicitly in the documentation on npm (https://www.npmjs.com/package/js-linq).

I import it with the usual syntax import { Linq } from 'js-linq' and then try to use it in my React project according to the documentation: const items = Linq.from([1, 2, 3, 4, 5]).

There are no typescript errors or anything suggesting the import is bad.

But at runtime it fails, saying Linq is undefined.

What am I doing wrong here?

2

Answers


  1. It seems like the types in this package in jslinq.ts don’t match up with what’s actually exported in the Javascript jslinq.js. You can get it to work as follows:

    import Linq from 'js-linq'
    console.log(Linq)
    // doesn't work despite the types suggesting it should
    // const items = new Linq.Linq([1, 2, 3, 4, 5])
    
    // this works
    // @ts-ignore
    const items = Linq.from([1, 2, 3, 4, 5])
    console.log(items.where((x) => x > 2).toArray()) // [3, 4, 5]
    
    
    Login or Signup to reply.
  2. Please use yarn

    • Install it using : npm install –global yarn
    • Then install your dependency: yarn add js-linq
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search