Skip to content

Accessing undefined input properties returns never type instead of compilation error #2760

@ThomasKientz

Description

@ThomasKientz

Description

When accessing undefined properties on the input object results in a never type instead of a TypeScript compilation error.

const helloWorldEndpoint = defaultEndpointsFactory.build({
  input: z.object({
    foo: z.string(),
  }),
  output: z.object({
    foo: z.string(),
  }),
  handler: async ({ input: { bar, foo } }) => {
    console.log(bar) // <----------------------- bar: never
    return { foo };
  },
});

Preferred Behavior

I'd prefer TypeScript to throw a clear compilation error such as:

Property 'foo' does not exist on type ...'

This would make debugging easier and catch typos at compile time rather than having to discover the never type through hovering or other means.

The never type essentially silences what should be a helpful TypeScript error, making it harder to catch mistakes during development.

Context

  • express-zod-api version: 24.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions