Skip to content

Best practice for valibot to work with typescript's isolated declarations feature #968

Open
@hyf0

Description

With enabling https://www.typescriptlang.org/tsconfig/#isolatedDeclarations, tsc require to write code with explicit type annotations:

For exmaple:

The case in README.md

const LoginSchema: /* tsc force you write type here, so what should be write here for valibot? */ = v.object({
  email: v.pipe(v.string(), v.email()),
  password: v.pipe(v.string(), v.minLength(8)),
});

For small schemas, I could just type them there. But I have very big schemas which isn't proper to manually write them.

zod has a helper type ZodType to infer schemas from types. So for zod, it could be written as

const LoginSchema: ZodType<{ email: string, passworld: string }> = v.object({
  email: v.pipe(v.string(), v.email()),
  password: v.pipe(v.string(), v.minLength(8)),
});

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions