toeverything/AFFiNE · error · Error

[Table(${table.name})]: Field '${key}' type mismatch. Expect

Error message

[Table(${table.name})]: Field '${key}' type mismatch. Expected ${field.type} got ${typeGet}.

What it means

A DataTypeShouldMatch validator case for non-enum fields: the runtime-observed input type of the value (computed by inputType) does not equal the schema-declared field.type. It fires on insert/update when, e.g., a string is supplied for a number field; the faulting input is data[key] whose dynamic type mismatches the schema for the named table.

Source

Thrown at packages/common/infra/src/orm/core/validators/data.ts:81

          if (val === null) {
            if (!field.optional) {
              throw new Error(
                `[Table(${table.name})]: Field '${key}' is required but not set.`
              );
            }
            continue;
          }

          const typeGet = inputType(val);

          if (field.type === 'enum') {
            if (!field.values?.includes(val)) {
              throw new Error(
                `[Table(${table.name})]: Field '${key}' value '${val}' is not valid. Expected one of [${field.values?.join(', ')}].`
              );
            }
          } else if (!typeMatches(field.type, typeGet)) {
            throw new Error(
              `[Table(${table.name})]: Field '${key}' type mismatch. Expected ${field.type} got ${typeGet}.`
            );
          }
        } else if (!table.isDocumentTable) {
          // strict check field existence for normal table
          throw new Error(
            `[Table(${table.name})]: Field '${key}' is not defined but set in entity.`
          );
        }
      }
    },
  },
  DataTypeShouldExactlyMatch: {
    validate(table, data) {
      const keys: Set<string> = new Set();

      for (const key in data) {
        const field = table.schema[key];

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Convert the value to the field's declared type before saving.
  2. Fix the schema type declaration if it does not match the data actually stored.
  3. Check for serialization issues, e.g. numbers arriving as strings.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/common/infra/src/orm/core/validators/data.ts:81 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/632ced507ac795ee. Report an issue: GitHub.