Skip to content

Should InferInput instead of InferOutput on Standard Schema validation #224

@aboqasem

Description

@aboqasem

What version of Elysia is running?

No response

What platform is your computer?

No response

What steps can reproduce the bug?

Try on https://elysiajs.com/playground:

import { Elysia } from 'elysia';
import { StandardSchemaV1Like } from 'elysia/types';
import { treaty } from '@elysiajs/eden';
import * as z from 'zod';

const QuerySchema = z.object({
    name: z.string().default("World"),
});

const app = new Elysia()
	.get('/', ({ query: { name } }) => `Hello ${name}!`, { query: QuerySchema })
	.listen(3000);

const api = treaty(app);

api.get({ query: { name: "Elysia" } });

// TS ERROR, SHOULD WORK
api.get({ query: {} });

// Zod:
// type QueryInput = z.input<typeof QuerySchema>;

// Standard Schema: https://github.com/standard-schema/standard-schema#the-interface
export type InferInput<Schema extends StandardSchemaV1Like> = NonNullable<
Schema['~standard']['types']
>['input'];

export type QueryInput = InferInput<typeof QuerySchema>;

const query: QueryInput = {};

// TS ERROR, SHOULD WORK
api.get({ query });

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

See:

Have you try removing the node_modules and bun.lockb and try again yet?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions