{"id":15688,"library":"linqts","title":"LinQ for TypeScript","description":"linqts is a TypeScript library that ports LINQ (Language Integrated Query) capabilities, familiar to C# developers, to JavaScript and TypeScript environments. It provides a `List<T>` class that offers a rich set of methods for querying and manipulating collections in a fluent, declarative style, including operations like `Where`, `Select`, `Join`, `GroupBy`, `Min`, and `Max`. The library is currently stable at version 3.2.0 and maintains an active development cadence with major releases approximately annually and more frequent minor and patch updates addressing features and bug fixes. Its primary differentiator is the direct porting of the LINQ API surface, which makes it intuitive for developers coming from a .NET background, providing strong type safety through TypeScript.","status":"active","version":"3.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/kutyel/linq.ts","tags":["javascript","linq","typescript"],"install":[{"cmd":"npm install linqts","lang":"bash","label":"npm"},{"cmd":"yarn add linqts","lang":"bash","label":"yarn"},{"cmd":"pnpm add linqts","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `List` class is the primary export and entry point for all LinQ-like operations. It's intended for ESM and TypeScript usage. For CommonJS, `require('linqts').List` is the typical access pattern.","wrong":"const List = require('linqts').List;","symbol":"List","correct":"import { List } from 'linqts';"},{"note":"The `List` class is a named export, not a default export. Attempting to import it as a default will result in an undefined `List`.","wrong":"import List from 'linqts'; new List<MyType>(myArray);","symbol":"ListConstructor","correct":"import { List } from 'linqts'; new List<MyType>(myArray);"},{"note":"Since v1.15.0, `List` instances are iterable, allowing use with `for...of` loops and spread syntax. Older versions may not support this directly.","wrong":"import { List } from 'linqts'; const myList = new List([1,2,3]); for (const item of myList) {}","symbol":"Iterable/Spread","correct":"import { List } from 'linqts'; const myList = new List([1,2,3]); [...myList]"}],"quickstart":{"code":"import { List } from 'linqts';\n\ninterface Person { Name: string; Age: number; } \ninterface Pet { Name: string; Owner: Person; Type: string; }\n\nconst people: Person[] = [\n  { Name: 'Alice', Age: 30 },\n  { Name: 'Bob', Age: 25 },\n  { Name: 'Charlie', Age: 35 }\n];\n\nconst pets: Pet[] = [\n  { Name: 'Fido', Owner: people[0], Type: 'Dog' },\n  { Name: 'Whiskers', Owner: people[1], Type: 'Cat' },\n  { Name: 'Buddy', Owner: people[0], Type: 'Dog' }\n];\n\n// Example 1: Filtering and mapping\nconst youngAdultsNames = new List(people)\n  .Where(p => p.Age < 30)\n  .Select(p => p.Name)\n  .ToArray();\nconsole.log('Young Adults Names:', youngAdultsNames); // Expected: ['Bob']\n\n// Example 2: Joining collections\nconst petsByOwner = new List(people).Join(\n  pets,\n  person => person,\n  pet => pet.Owner,\n  (person, pet) => ({ OwnerName: person.Name, PetName: pet.Name, PetType: pet.Type })\n);\nconsole.log('Pets by Owner:', petsByOwner.ToArray());\n/* Expected: [\n  { OwnerName: 'Alice', PetName: 'Fido', PetType: 'Dog' },\n  { OwnerName: 'Bob', PetName: 'Whiskers', PetType: 'Cat' },\n  { OwnerName: 'Alice', PetName: 'Buddy', PetType: 'Dog' }\n]*/","lang":"typescript","description":"This quickstart demonstrates basic filtering, mapping, and joining operations using the `List` class to perform LinQ-style queries on in-memory collections."},"warnings":[{"fix":"Review calls to `Min()` and `Max()` to ensure correct generic type arguments or selectors are provided, especially if working with complex objects. For example, `list.Min(x => x.property)`.","message":"The `Min()` and `Max()` functions are now generic. Code relying on the non-generic versions or specific type inference may require updates.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Carefully test existing code that uses `ToDictionary()` or any `*OrDefault()` methods. Update logic if their new behavior (especially regarding default values for `*OrDefault` and key collisions for `ToDictionary`) no longer aligns with assumptions. Ensure your `tsconfig.json` is configured correctly for strict mode if enabling it.","message":"The behavior of `ToDictionary()` and all `*OrDefault()` functions (e.g., `FirstOrDefault()`, `SingleOrDefault()`) changed significantly, primarily due to stricter TypeScript support. Additionally, strict mode support was introduced.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"If your code previously relied on `ElementAtOrDefault()` throwing an error for out-of-range indices, you must update it to explicitly check for `undefined` return values.","message":"`ElementAtOrDefault()` was fixed to return `undefined` when the index is out of range, instead of throwing an error. This is a behavioral change.","severity":"gotcha","affected_versions":">=1.14.0"},{"fix":"Ensure you are using `linqts@1.14.4` or newer to avoid potential CommonJS module resolution issues in TypeScript projects.","message":"Older versions (prior to v1.14.4) had issues with module resolution for TypeScript projects when building for CommonJS, potentially causing errors.","severity":"gotcha","affected_versions":"<1.14.4"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Provide a selector function to `Min()` or `Max()` to specify the property to compare, e.g., `list.Min(item => item.value)`.","cause":"Attempting to use `Min()` or `Max()` without providing a selector function or incorrect generic types after v3.0.0 made these methods generic.","error":"TypeError: list.Min is not a function or TypeError: Argument of type '(x: SomeType) => string' is not assignable to parameter of type '((arg: T) => number) | undefined'"},{"fix":"Ensure you use `import { List } from 'linqts';` for ESM/TypeScript or `const { List } = require('linqts');` for CommonJS.","cause":"Incorrect import statement for the `List` class, often attempting to use a default import instead of a named import, or incorrect CommonJS require.","error":"TypeError: Cannot read properties of undefined (reading 'Where') or TypeError: List is not a constructor"},{"fix":"Consult the `linqts` documentation for `ToDictionary()` in version 2.0.0 and above. Ensure your key selector returns unique keys or handle potential collisions as per the new behavior.","cause":"Usage of `ToDictionary()` with an incorrect signature or misunderstanding its updated behavior after v2.0.0, especially regarding strict mode implications or key uniqueness.","error":"Property 'ToDictionary' does not exist on type 'List<MyType>' or runtime error with unexpected `ToDictionary` behavior."}],"ecosystem":"npm"}