can1357/oh-my-pi · error · OmpTypeError

Type.${operation} requires a schema created by Type.Object

Error message

Type.${operation} requires a schema created by Type.Object

What it means

Object-only combinators (`Type.Partial`, `Type.Required`, `Type.Omit`, `Type.Pick`, etc.) look up an internal OBJECT_INFO marker installed by `Type.Object`. `requireObject` throws `Type.<operation> requires a schema created by Type.Object` when the schema passed in lacks that marker, meaning it was built by any other constructor (tString, tArray, unions, or a plain TypeBox/zod schema).

Source

Thrown at packages/omptype/src/typebox.ts:458

	return applyMeta(base, opts) as TRecord<K, V>;
}

function tOptional<E extends AnySchema>(schema: E, opts?: Meta): TOptional<E> {
	const marker = applyMeta(
		asRuntime<Static<E>>(schema).or(asRuntime<undefined>(type.raw("undefined"))),
		opts,
	) as RuntimeType<Static<E> | undefined>;
	marker[OPTIONAL_INNER] = schema;
	return marker as unknown as TOptional<E>;
}

function tNullable<E extends AnySchema>(schema: E, opts?: Meta): TTyped<Static<E> | null> {
	return applyMeta(asRuntime<Static<E>>(schema).or(asRuntime<null>(type.raw("null"))), opts);
}

function requireObject(schema: AnySchema, operation: string): ObjectInfo {
	const info = asRuntime<unknown>(schema)[OBJECT_INFO];
	if (!info) throw new OmpTypeError(`Type.${operation} requires a schema created by Type.Object`);
	return info;
}

function tPartial<P extends Record<string, AnySchema>>(schema: TObject<P>): TTyped<Partial<ObjectStatic<P>>> {
	const info = requireObject(schema, "Partial");
	const props: Record<string, AnySchema> = {};
	for (const key in info.props)
		props[key] = asRuntime<unknown>(info.props[key])[OPTIONAL_INNER] ? info.props[key] : tOptional(info.props[key]);
	return tObject(props, { additionalProperties: info.additionalProperties }) as TTyped<Partial<ObjectStatic<P>>>;
}

function tRequired<P extends Record<string, AnySchema>>(schema: TObject<P>): TObject<RequiredProps<P>> {
	const info = requireObject(schema, "Required");
	const props: Record<string, AnySchema> = {};
	for (const key in info.props) {
		props[key] = asRuntime<unknown>(info.props[key])[OPTIONAL_INNER] ?? info.props[key];
	}
	return tObject(props, { additionalProperties: info.additionalProperties }) as TObject<RequiredProps<P>>;

View on GitHub (pinned to 9690622007)

Solutions

  1. Ensure the schema argument was created with omptype's `Type.Object({...})`, not another constructor or library.
  2. Check the call site after field-type refactors: if the property is no longer an object, drop or replace the Partial/Pick/Required call.
  3. If working with a raw typebox TObject, rebuild it through omptype's Type.Object so OBJECT_INFO gets attached.

Example fix

// before
const partial = Type.Partial(tArray(tString()));
// after
const config = Type.Object({ id: tString(), tags: tArray(tString()) });
const partial = Type.Partial(config);
Defensive patterns

Strategy: type-guard

Validate before calling

// pass only Type.Object results into object combinators
const config = Type.Object({ id: tString(), tags: tArray(tString()) });
const partial = Type.Partial(config);

Type guard

function isOmpObjectSchema(s: unknown): s is TObject<Record<string, AnySchema>> {
  return typeof s === 'object' && s !== null && (s as Record<symbol, unknown>)[OBJECT_INFO] !== undefined;
}

Try / catch

try {
  const partial = Type.Partial(maybeObject);
} catch (err) {
  if (err instanceof Error && err.message.includes('requires a schema created by Type.Object')) {
    throw new Error(`Partial/Omit/Pick need Type.Object input; got a non-object schema`);
  }
  throw err;
}

Prevention

When it happens

Trigger: `Type.Partial(tString())`, applying `Type.Omit` to a union or array schema, or passing a schema from a foreign schema library (raw typebox/zod object) that omptype's `Type.Object` never tagged.

Common situations: Refactoring a field type from an object to an array/string without updating the downstream Partial/Pick call; mixing omptype `Type.*` helpers with schemas produced by other builders; passing `TObject` from plain typebox instead of omptype's `Type.Object`.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/137196cc349d78b2. Report an issue: GitHub.