kutyel / linq.ts

🌀LINQ for TypeScript

Home Page:http://kutyel.github.io/linq.ts/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type definition wrong?

uler3161 opened this issue · comments

Just found this project and would love to be able to use linq style code in typescript. However, I think there's something wrong with the typings file. It's almost like it's out of date. Specifically, I'm trying to use the GroupBy changes in 1.12.1. I've tried that version and 1.12.2. Both seem to have this in index.d.ts:

GroupBy(grouper: (key: T) => any, mapper: (element: T) => any): any;

I'll admit that I'm fairly new to typescript, so maybe I'm missing something, but isn't that the wrong entry?

Hi! Thanks for reporting this! Indeed, I tried to run microbundle locally and it seems that the build option is not working, therefore in the last publish the definitions were not updated, @developit do you know what could be wrong with the bundler? 🤔

So, out of curiosity... if LinqTS is itself a TypeScript file, why does it need a d.ts file? Why not just ship the .ts file and let the TypeScript compiler do all the work?

So, out of curiosity... if LinqTS is itself a TypeScript file, why does it need a d.ts file? Why not just ship the .ts file and let the TypeScript compiler do all the work?

Like I said, I'm fairly new to Typescript, so maybe I'm not understanding correctly, but I believe this is what's defining things as having a type rather than "any". That's much better for intellisense.

Another reason is my development environment is showing an error when I try to use GroupBy with just a grouper. I believe that's because the old index.d.ts requires both a grouper and a mapper, but the new one appears to have mapper as optional.

@Uler, I'm sorry, that question was for @kutyel.

@robertmclaws you are right, the whole project is TypeScript so a *.d.ts file should not be needed but I use microbundle to bundle and compile to different targets and so consumers of the lib should need the unified type definition file. @uler3161 can you try and change the package.json for the library in your node_modules to this?

"types": "index.ts",

If that works for you I'll make a new release with that changed and it should work! 😉

Maybe this is all due to the fact that I had to stuck the project to microbundle@0.4.0, @texastoland do you know what I need to change to benefit from the upgrading to TypeScript 3 and the latest version of microbundle? 🙏

I think the point of shipping it as a TypeScript file is that it gets compiled by the end project, and doesn't get transpiled to something else in between. There are other implementations (like linqjs) that are frankly a little better in some ways, so this project should play to it's strengths (more closely mapping to the C# LINQ implementation) and keep things simple. Just ship the TS file. Don't transpile it, don't have a separate types file. None of that is necessary. If you're not using TypeScript in the first place, I don't think you should be using this library. But that's just my personal opinion :)

I tried very hard at the beginning of the library to ship just TypeScript, and I ended up having a new Issue per week of Angular people not being able to actually use the library on their projects...

I wrestled with TypeScript in microbundle including several PRs. I found deeper issues and ended up falling back to Rollup. Wish I could help!