{"record":{"id":"941365d12332dad2","repo":"eythaann/Seelen-UI","slug":"the-inner-array-must-be-an-array","errorCode":null,"errorMessage":"The inner array must be an array.","messagePattern":"The inner array must be an array\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"libs/core/src/utils/List.ts","lineNumber":16,"sourceCode":"/**\n * A generic, abstract class for managing an array-like collection of items.\n * @template T The type of elements stored in the list.\n */\nexport abstract class List<T = unknown> {\n  /**\n   * Constructor for the List class.\n   * @param inner The internal array that stores the elements.\n   * @throws Error if the provided array is not\n   */\n  constructor(protected inner: T[]) {\n    if (!inner) {\n      throw new Error(\"The inner array cannot be null or undefined.\");\n    }\n    if (!Array.isArray(inner)) {\n      throw new Error(\"The inner array must be an array.\");\n    }\n  }\n\n  public [Symbol.iterator](): Iterable<T> {\n    return this.inner[Symbol.iterator]();\n  }\n\n  public get length(): number {\n    return this.inner.length;\n  }\n\n  /**\n   * Provides direct access to the internal array of items.\n   * @returns A reference to the internal array of items.\n   */\n  public asArray(): T[] {\n    return this.inner;\n  }","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/eythaann/Seelen-UI/blob/dee4aaa94066c5d0888ab25554864862fc47be15/libs/core/src/utils/List.ts#L1-L34","documentation":"After the null check, List's constructor verifies with Array.isArray that the inner value is actually an array. Passing a non-array value (string, plain object, Set/Map, typed array) is rejected because List relies on array semantics for its internal storage.","triggerScenarios":"new List({} | 'abc' | someSet | someMap) — passing an object, string, or other non-array collection; passing a value typed as T[] at compile time via an unsafe cast or any-typed API data that is not an array at runtime.","commonSituations":"Unsafe `data as T[]` casts hiding that the API returned an object whose data field holds the real array; passing a single element instead of an array; refactors changing a producer from array to object without updating consumers.","solutions":["Ensure you pass an actual array: new List(Array.isArray(x) ? x : []) or Object.values(x) for map-like objects.","Remove unsafe `as T[]` casts and type the source properly so TypeScript flags non-arrays.","Validate/parse incoming data with a schema (zod/yup) that asserts an array before constructing List.","Spread iterables into arrays: new List([...setOrIterable])."],"exampleFix":"// before: const list = new List(response.items as string[]); // actually an object\n// after: const items = Array.isArray(response.items) ? response.items : []; const list = new List(items);","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(items)) throw new TypeError('List requires a real array, got: ' + typeof items); const list = new List(items);","typeGuard":"function is_array<T>(v: unknown): v is T[] { return Array.isArray(v); }","tryCatchPattern":"let list: List<T>; try { list = new List(untrusted as T[]); } catch (e) { if (e instanceof Error && e.message.includes('must be an array')) { list = new List(Object.values(untrusted as Record<string, T>)); } else { throw e; } }","preventionTips":["Avoid `as T[]` casts on untrusted data; use Array.isArray narrowing.","Wrap iterables/Sets/Maps with [...iterable] before constructing List.","Schema-validate external payloads so arrays are arrays at runtime.","When a producer changes shape, update all List consumers."],"tags":["validation","constructor","type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"dee4aaa94066c5d0888ab25554864862fc47be15","analyzedAt":"2026-09-03T10:20:37.842Z","contentChangedAt":"2026-09-03T10:20:37.842Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}