Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerable.from(array) is not working in angular library project #76

Open
jayakrishnankg opened this issue Apr 3, 2020 · 3 comments
Open

Comments

@jayakrishnankg
Copy link

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.

@mihaifm
Copy link
Owner

mihaifm commented Apr 3, 2020

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.

@alexkunin
Copy link

alexkunin commented Dec 26, 2021

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.

@JeffersonFerreira
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants