sequelize/sequelize · error · TypeError
Could not guess type of value ${logger.inspect(val)}
Error message
Could not guess type of value ${logger.inspect(val)} What it means
Sequelize throws this when it must serialize a value to SQL but no data type was declared for it, so it falls back to bestGuessDataTypeOfVal to infer one from the JS value. The function handles bigint, number, boolean, string, Date, Buffer, and arrays, but rejects anything else. Hitting the catch-all throw means the value is null/undefined/symbol/function or a plain object the dialect cannot map to a column type.
Source
Thrown at packages/core/src/sql-string.ts:71
if (Buffer.isBuffer(val)) {
// TODO: remove dialect-specific hack
if (dialect.name === 'ibmi') {
return new DataTypes.STRING().toDialectDataType(dialect);
}
return new DataTypes.BLOB().toDialectDataType(dialect);
}
break;
case 'string':
return getTextDataTypeForDialect(dialect);
default:
}
throw new TypeError(`Could not guess type of value ${logger.inspect(val)}`);
}
View on GitHub (pinned to 7e1deec499)
Solutions
- Ensure the value is defined before querying; convert `undefined` to `null` explicitly so sequelize emits NULL.
- Provide an explicit DataType on the column or in the query options so sequelize does not have to guess.
- Serialize custom objects (class instances, Map/Set) to a primitive (string/number) or Buffer/Date before passing them.
- If you genuinely need to store structured data, use a JSON column and pass a serializable plain object via the model's DataType, not a raw value through the inferrer.
Example fix
// before
await User.findAll({ where: { email: maybeUndefined } }); // maybeUndefined is undefined
// after
await User.findAll({ where: { email: maybeUndefined ?? null } }); Defensive patterns
Strategy: validation
Validate before calling
function isValidQueryableValue(v) {
if (v === undefined) return false;
const t = typeof v;
if (t === 'symbol' || t === 'function') return false;
if (v === null) return true; // handled as NULL
if (t === 'bigint' || t === 'number' || t === 'boolean' || t === 'string') return true;
if (v instanceof Date || Buffer.isBuffer(v)) return true;
if (Array.isArray(v)) return v.length > 0 && isValidQueryableValue(v[0]);
return false; // plain object, Map, Set, class instance
}
// before querying:
const value = maybeUndef ?? null;
if (!isValidQueryableValue(value)) throw new TypeError(`Unsupported query value: ${value}`); Type guard
function isInferrableValue(v: unknown): v is string | number | bigint | boolean | Date | Buffer | Array<unknown> {
if (v == null || typeof v === 'symbol' || typeof v === 'function') return false;
if (v instanceof Date || Buffer.isBuffer(v)) return true;
if (Array.isArray(v)) return v.length > 0 && isInferrableValue(v[0]);
return ['string','number','bigint','boolean'].includes(typeof v);
} Prevention
- Always coerce undefined to null at the boundary where query values enter your code.
- Declare explicit DataTypes on columns so sequelize never has to infer.
- Serialize class instances/Map/Set to primitives or use JSON columns.
- Add a runtime assertion in dev/test that asserts every where-value is inferrable.
When it happens
Trigger: Called from AbstractQueryGenerator#escape value path (query-generator-typescript.ts:867) when `type` is null/undefined or a raw string. Produces it for: a WHERE literal of `undefined`/`null` reaching the inferrer instead of being short-circuited, a `Symbol`, a `function`, a class instance, or a plain object (not Date/Buffer/Array) used as a query value or bind param without an explicit DataType.
Common situations: Passing `undefined` instead of `null` in a where value (e.g. `{ where: { id: someVar } }` where someVar is undefined); storing a custom class instance or Map/Set without declaring its DataType; raw queries with `QueryTypes` values sequelize can't introspect; upgrading from v6 where some values were stringified silently.
Related errors
- The following literal includes positional replacements (?).
- The argument passed to findAll must be an options object, us
- The attributes option must be an array of column names or an
- ${name} is not a recognized built-in modifier. Here is the l
- Constraint type ${type} is not supported
AI-assisted analysis of sequelize/sequelize@7e1deec499 (2026-08-03).
Data as JSON: /data/errors/9f9196f7bc65316c.json.
Report an issue: GitHub.