Enumerable.from(array) is not working in angular library project
jayakrishnankg opened this issue · comments
I have created an angular library project and I am using 'linq' in that project.
import * as Enumerable from 'linq'; Enumerable.from(array).firstOrDefault(a => a == 'somestring'); //fails at Enumerable.from
I am getting the following exception at Enumerable.from(array):
{description: "Function expected", message: "Function expected", number: -2146823286, stack: "TypeError: Function expected at Anonymous function"......."
Interestingly the same line of code works perfectly in the main angular application but not in the library. Please let me know if something needs to be handled at the library project.
Any help would be great. @mihaifm please help me
Thanks.
Sorry, no idea what causes that error, I'm not familiar with angular libraries.
Try to isolate the problem and create a small example that can be easily replicated, otherwise it would be difficult to get help.
I have similar problem with Jest tests in Angular project, it has { "globals": { "ts-jest": { "isolatedModules": true } } }
, which basically means Types are not compiled, but stripped.
If I import linq
as docs suggest:
import { Enumerable } from 'linq';
I get the following error message (points to the line with Enumerable.from
):
TypeError: Cannot read properties of undefined (reading 'from')
But if I import from
directly (I still need Enumerable
namespace itself, for typing purposes)):
import Enumerable, { from } from 'linq';
then the problem goes away.
And when compiled with ng build
or ng serve
(weback
does all the thing), it works both ways. AFAIK Angular libraries are built via rollup
(you can check this here: https://github.com/ng-packagr/ng-packagr/blob/master/package.json), and Jest also does not do full webpack
-style compilation.
@mihaifm, does this help?
Update: Just tested import * as Enumerable from 'linq';
, and it seems to also work in both Angular and Jest environments.
Hey @alexkunin thanks for reporting your tests, sadly it didn't worked for me.
I'm using linq with React, using the default jest implementation.