Skip to content

type hints when all query params are optional are lost #217

@abhishekg999

Description

@abhishekg999

What version of Elysia is running?

1.4.10

What platform is your computer?

Darwin 24.3.0 arm64 arm

What steps can reproduce the bug?

import { Elysia, t } from 'elysia'
import { treaty } from './src/treaty2'

const app = new Elysia().get('/optional', ({ query: { name } }) => name, {
    query: t.Object({
        name: t.Optional(t.String())
    })
})

export type App = typeof app

const api = treaty<App>('localhost:8080')
type QueryParams = NonNullable<Parameters<typeof api.optional.get>[0]>['query']
// type QueryParams = Record<string, unknown> | undefined

What is the expected behavior?

The type of QueryParams should give some hinting as to the name. Either:

type QueryParams = { name?: string | undefined; } | undefined

or to preserve existing behavior, with additional type hints:

type QueryParams = ({ name?: string | undefined; } & Record<string, unknown>) | undefined

What do you see instead?

type QueryParams = Record<string, unknown> | undefined

Additional information

The same probably follow for headers as well that has the same inference logic as query.

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

yes

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