montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.09k stars 185 forks source link

How to use collections in Angular? #240

Open audetto opened 4 years ago

audetto commented 4 years ago

Probably doing something wrong here

npm install collections npm install @types/collections

then I tried to import in various ways

import as collections from 'collections/sorted-set'; or import as collections from 'collections';

but the best I get is a runtime error

ReferenceError: global is not defined

at

generic-collection.js:8

How do I do it?

leandro-manifesto commented 4 years ago

The latest @types/collections (5.0.2) is basically empty, so I needed to roll my own declaration files to be able to use the package in a TypeScript.

Would be nice if the package itself provided type declarations.

icfantv commented 4 years ago

I mean, not to be blunt, but this is how OSS works. See a need, fill a need. Does it take time? Yep. Can it be a PITA? Yep. Is everyone so lucky as to be in a position at work where they are allowed/able to contribute to OSS? Nope. But if everyone contributed a line or two, it'd be done quite quickly.

JesusTheHun commented 2 years ago

While I agree with you @icfantv , contribution comes from adoption. Lack of TS support means lower adoption. Also while I would love to contribute by creating the types, you must admit that creating the declaration files requires a solid knowledge of this lib.

nicoxxl commented 1 year ago

I am using vue3/vite, without @types/collections and I have the same error.

It seems to be coming from this line :

var DOMTokenList = global.DOMTokenList || function(){};

And as stated by MDN, global only exist for node. If I understood it correctly, this fix should be simply using globalThis instead of global.