seangenabe / starry

[DEPRECATED. Please direct efforts to the awesome `ix` library.] Modular functions for iterable objects
MIT License
4 stars 0 forks source link

can't figure out how to import into Typescript #24

Open jmagaram opened 6 years ago

jmagaram commented 6 years ago

I added this to package.json...

"starry.map": "3.0.0",
"starry.group-by": "3.0.1",
"starry.filter": "3.0.0"

What is easiest way to add to my TypeScript files? I've tried this...

import * as filter from 'starry.filter';
import * as groupBy from 'starry.group-by';
import * as map from 'starry.map';

And it all auto-completes and does IntelliSense fine, EXCEPT for red squiggly under the GroupBy import. I get this error...

Module '"c:/Users/justi/source/repos/gtd/node_modules/starry.group-by/index"' resolves to a non-module entity and cannot be imported using this construct.

Not sure why groupBy gives a problem but the other ones work fine. Also, it is tedious to import each function that way. Is there a shorthand? I'm just learning TypeScript.

jmagaram commented 6 years ago

Going crazy here. I really want to use your library. Looks like a lot of care went into making it. I like the dot-free extensible notation and that it is built using Typescript and has lots of good docs. But I can't get going with it at all. After adding to package.json, I would expect these lines to work but errors about "has no exported member filter". Try it here: code sandbox

import { filter as flt } from 'starry.filter' import { groupBy as grp } from 'starry.group-by' const x = flt([1,2,3,4,5],i=>i!==2);

seangenabe commented 6 years ago

import filter = require('starry.filter') is the correct syntax right now, but I've been thinking about exporting a default and named export instead as that works better in VSCode. 🤔

jmagaram commented 6 years ago

In a TypeScript file in VS code import filter = require('starry.filter') gives me...

Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.

Then I tried this...

 import { filter } from 'starry.filter';

And got this...

Module '"c:/Users/justi/source/repos/gtd/node_modules/starry.filter/index"' has no exported member 'filter'.

seangenabe commented 6 years ago

You're targeting es6 as your output module format. You can either switch to commonjs modules in your tsconfig.json or use the import * as ns from 'module' format.

Looks like there's a bug specific to groupBy.

seangenabe commented 6 years ago

Have you managed to fix this? You can check the tests to see how the function is being imported.