{"id":"a6e681a1f9162209","repo":"sindresorhus/is","slug":"expected-value-which-is-tuple-like-received-val","errorCode":null,"errorMessage":"Expected value which is `tuple-like`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `tuple-like`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1914,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('string', value));\n\t}\n}\n\nexport function assertSymbol(value: unknown, message?: string): asserts value is symbol {\n\tif (!isSymbol(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('symbol', value));\n\t}\n}\n\nexport function assertTruthy<T>(value: T | Falsy, message?: string): asserts value is T {\n\tif (!isTruthy(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('truthy', value));\n\t}\n}\n\nexport function assertTupleLike<T extends Array<TypeGuard<unknown>>>(value: unknown, guards: [...T], message?: string): asserts value is ResolveTypesOfTypeGuardsTuple<T> {\n\tif (!isTupleLike(value, guards)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('tuple-like', value));\n\t}\n}\n\nexport function assertTypedArray(value: unknown, message?: string): asserts value is TypedArray {\n\tif (!isTypedArray(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('TypedArray', value));\n\t}\n}\n\nexport function assertUint16Array(value: unknown, message?: string): asserts value is Uint16Array {\n\tif (!isUint16Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint16Array', value));\n\t}\n}\n\nexport function assertUint32Array(value: unknown, message?: string): asserts value is Uint32Array {\n\tif (!isUint32Array(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Uint32Array', value));","sourceCodeStart":1896,"sourceCodeEnd":1932,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1896-L1932","documentation":"Thrown by `assert.tupleLike()` (assertTupleLike at source/index.ts:1912) when `isTupleLike(value, guards)` fails. Unlike the other assertions it takes a second argument: an array of type guards, one per tuple position. The value must be an array whose length equals `guards.length` AND where every element passes its corresponding guard — a length mismatch or one wrong-typed element fails the whole assertion.","triggerScenarios":"Calling `assert.tupleLike(value, [is.number, is.string])` with a non-array, an array of the wrong length (e.g. 3 elements against 2 guards), or an array where some position fails its guard (e.g. `['1', 'a']` where index 0 must be a number).","commonSituations":"Destructuring API responses expected as fixed pairs (`[lat, lng]`, `[key, value]`) where the server added/removed fields; CSV or split-string rows with missing columns; numeric positions arriving as strings after JSON/query-string parsing; passing the guards array with the wrong arity after refactoring the tuple shape.","solutions":["Check the tuple length: the guards array length must exactly match the value's length — update the guards when the tuple shape changes.","Verify each element's type against its positional guard; coerce upstream (e.g. `Number(parts[0])`) where parsing produced strings.","If trailing elements are optional, validate with a custom check or `is.array` plus per-element guards instead of tupleLike."],"exampleFix":"// before\nconst pair = line.split(','); // ['12.5', 'label'] — strings\nassert.tupleLike(pair, [is.number, is.string]);\n// after\nconst parts = line.split(',');\nconst pair = [Number(parts[0]), parts[1]];\nassert.tupleLike(pair, [is.number, is.string]);","handlingStrategy":"validation","validationCode":"if (!Array.isArray(value) || value.length !== expectedLength) {\n  throw new TypeError(`Expected a tuple of length ${expectedLength}`);\n}","typeGuard":"function isTupleOfLength<N extends number>(value: unknown, length: N): value is unknown[] & {length: N} {\n  return Array.isArray(value) && value.length === length;\n}","tryCatchPattern":"try {\n  assert.tupleLike(value, guards);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // wrong length or an element failed its per-position guard\n  }\n  throw error;\n}","preventionTips":["Verify both Array.isArray and the exact length — tuple checks are positional, extra or missing elements fail","Validate each position's type before asserting (e.g. [is.string, is.number] element-wise)","Use TypeScript tuple types ([string, number]) and 'as const' at construction so the compiler enforces the shape"],"tags":["typescript","type-assertion","tuple","array","validation"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}