awslabs/llrt · error · TypeError
value must be , received
Error message
${name} value must be ${types.join(" or ")}, received "${receivedType}" What it means
This TypeError is thrown by the `assertTypes` helper in @llrt/expect, used by matchers to validate that the expectation value has one of the allowed JavaScript types. It computes `typeof value` and compares against the accepted type list; on mismatch it reports the expected types joined by 'or' and the actual received type. JestChaiExpect matchers call it before performing comparisons.
Solutions
- Convert the value to the expected type before asserting (Number('1.5'), etc.).
- Check the value with typeof / an if-guard before the matcher call.
- Fix the source of the value so it produces the intended type (often an API returned null).
Example fix
// before expect(result.rate).toBeCloseTo(0.5); // result.rate is '0.5' (string) // after expect(Number(result.rate)).toBeCloseTo(0.5);
Defensive patterns
Strategy: validation
Validate before calling
if (typeof value !== 'number') throw new TypeError('toBeCloseTo expects a number, got ' + typeof value); Type guard
function isType(v, ...types) {
return types.includes(typeof v);
} Prevention
- Coerce values at the boundary (Number(), String()) before asserting.
- Check for null/undefined from API responses before matching.
- Update tests when the shape of returned data changes.
When it happens
Trigger: Calling a matcher that internally asserts types, e.g. expect(x).toBeCloseTo(nonNumber) or expect(x).toMatchObject(nonObject) — any call where the runtime typeof of the value is not in the matcher's allowed types array.
Common situations: Passing null/undefined where a primitive is expected, passing a string number ('1.5') to toBeCloseTo, or refactors that changed a value's type without updating the test.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- You must provide a Promise to expect() when using…
- You must provide a Promise to expect() when using .rejects…
- You must provide an object to
- You must provide an array to
- "toThrow" expects string, RegExp, function, Error instance…
AI-assisted analysis of awslabs/llrt@742fc00b82 (2026-09-12).
Data as JSON: /api/errors/7ebb07abf1322e35.
Report an issue: GitHub.
Appendix: source
Thrown at llrt_core/src/modules/js/@llrt/expect/jest-expect.ts:634
return recordAsyncExpect(test, promise);
};
},
});
return proxy;
}
);
};
export function assertTypes(
value: unknown,
name: string,
types: string[]
): void {
const receivedType = typeof value;
const pass = types.includes(receivedType);
if (!pass)
throw new TypeError(
`${name} value must be ${types.join(" or ")}, received "${receivedType}"`
);
}
export function recordAsyncExpect(
test: any,
promise: Promise<any> | PromiseLike<any>
) {
// record promise for test, that resolves before test ends
if (test && promise instanceof Promise) {
// if promise is explicitly awaited, remove it from the list
promise = promise.finally(() => {
const index = test.promises.indexOf(promise);
if (index !== -1) test.promises.splice(index, 1);
});
// record promise
if (!test.promises) test.promises = [];View on GitHub (pinned to 742fc00b82)