Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript: InferInput always infers intersect as 'never' #601

Closed
naveen-bharathi opened this issue May 25, 2024 · 3 comments
Closed

TypeScript: InferInput always infers intersect as 'never' #601

naveen-bharathi opened this issue May 25, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@naveen-bharathi
Copy link

For any valibot schema that uses intersect, InferInput always infers intersect as type never

For the below code, the v.InferInput infers typeof eventSchema as never

This started in the first pre-release v0.31.0-rc.0 and still happens in the latest pre-release v0.31.0-rc.4

import * as v from 'valibot'

const eventSchema = v.intersect([
  v.pipe(
    v.object({
      name: v.pipe(
        v.string(),
        v.trim(),
        v.maxLength(128),
      ),
      startDate: v.date(),
      endDate: v.date(),
    }),
    v.check(({ startDate, endDate }) => startDate < endDate),
  ),
  v.variant('hasCelebrity', [
    v.object({
      hasCelebrity: v.literal(true),
      celebrity: v.literal('Fabian Hiller'),
    }),
    v.object({
      hasCelebrity: v.literal(false),
      celebrity: v.null_(),
    }),
  ]),
])

type EventSchemaT = v.InferInput<typeof eventSchema> // infers as 'never' (all the time)

Screenshot from VSCode Intellisense

SCR-20240525-igfe
@fabian-hiller
Copy link
Owner

Thanks for reporting this. I will fix it and release a new version.

@fabian-hiller fabian-hiller self-assigned this May 25, 2024
@fabian-hiller fabian-hiller added the bug Something isn't working label May 25, 2024
@fabian-hiller
Copy link
Owner

v0.31.0-rc.5 is available

@naveen-bharathi
Copy link
Author

Many Thanks @fabian-hiller
You're a super star ⭐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants