Skip to content
Discussion options

You must be logged in to vote

Hi @chrg1001! I'm Dosu and I’m helping the valibot team.

Valibot doesn't have a built-in instanceof or isSchema method for runtime schema detection, but you can reliably identify a Valibot schema by checking for the presence of the internal symbol Symbol.for('ValiType') on the object. This is the canonical marker used by Valibot for schema objects1.

Here's a TypeScript-compatible type guard you can use:

import type { GenericSchema } from 'valibot';

export function isValibotSchema(input: unknown): input is GenericSchema<unknown> {
  return (
    typeof input === 'object' &&
    input !== null &&
    Symbol.for('ValiType') in input
  );
}

This approach works for all standard Valibot schem…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by chrg1001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant