The `linked-list-typescript` package provides a straightforward, type-safe implementation of a doubly linked list in TypeScript. Currently stable at version 1.0.15, it emphasizes simplicity and strong typing through TypeScript generics. The library supports the JavaScript `Iterator` and `Iterable` protocols, enabling native iteration via `for...of` loops, spread syntax (`...`), and array destructuring. Key operations like retrieving head/tail elements, and removing head/tail are available. Unlike some data structures, it stores references to values rather than copies, which is important for understanding its behavior with mutable objects. The project appears to be in an active maintenance phase, with a focus on a stable 1.x release line.
npm install linked-list-typescriptVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to create a generic linked list, initialize it with values, iterate over its elements, deconstruct, and perform basic operations like removing the head, including usage with custom types.
Ensure all initial values passed to the `LinkedList` constructor conform to the specified generic type `T`. Use `LinkedList<any>` if heterogeneous types are intentionally required.
Always check if the list is empty (e.g., `list.length === 0` or `list.head !== undefined`) before attempting to access `head` or `tail` and their properties.
Be aware that changes to referenced objects will be reflected in the list. If immutable values are desired, ensure objects are not modified after insertion or create defensive copies before adding them.
Ensure all initial values match the generic type `T` specified for the `LinkedList`. For mixed types, explicitly use `new LinkedList<any>(...)`.
Before accessing properties on `list.head` or `list.tail`, verify that `list.head` (or `list.tail`) is not `undefined`, typically by checking `list.length > 0` or using optional chaining (`list.head?.property_name`).
Correct the import statement to use named exports: `import { LinkedList } from 'linked-list-typescript';`No dependency data recorded yet.