import * as vi from "vitest"
import * as v from 'valibot'
import { vx } from "@traversable/valibot"
vi.expect(vx.toType(
v.record(v.picklist(['a', 'b', 'c']), v.set(v.string()))
)).toMatchInlineSnapshot
(`"Record<"a" | "b" | "c", Set<string>>"`)
vi.expect(vx.toType(
v.objectWithRest({ a: v.optional(v.string()), b: v.number() }, v.boolean())
)).toMatchInlineSnapshot
(`"{ a?: string, b: number } & { [x: string]: boolean }"`)
vi.expect(vx.toType(
v.tupleWithRest([v.number()], v.boolean())
)).toMatchInlineSnapshot
(`"[number, ...boolean[]]"`)
// Use the `typeName` option to give you type a name:
vi.expect(vx.toType(
v.object({ a: v.optional(v.number()) }),
{ typeName: 'MyType' }
)).toMatchInlineSnapshot
(`"type MyType = { a?: number }"`)
vx.toType
Converts an arbitrary valibot schema into a string representing its underlying TypeScript type.
import * as vi from "vitest"
import * as v from 'valibot'
import { vx } from "@traversable/valibot"
vi.expect(vx.toType(
v.record(v.picklist(['a', 'b', 'c']), v.set(v.string()))
)).toMatchInlineSnapshot
(`"Record<"a" | "b" | "c", Set<string>>"`)
vi.expect(vx.toType(
v.objectWithRest({ a: v.optional(v.string()), b: v.number() }, v.boolean())
)).toMatchInlineSnapshot
(`"{ a?: string, b: number } & { [x: string]: boolean }"`)
vi.expect(vx.toType(
v.tupleWithRest([v.number()], v.boolean())
)).toMatchInlineSnapshot
(`"[number, ...boolean[]]"`)
// Use the `typeName` option to give you type a name:
vi.expect(vx.toType(
v.object({ a: v.optional(v.number()) }),
{ typeName: 'MyType' }
)).toMatchInlineSnapshot
(`"type MyType = { a?: number }"`)
vx.toType
Converts an arbitrary valibot schema into a string representing its underlying TypeScript type.