Skip to content

πŸ› Bug Report: Zod v4 type inference from schema not working properlyΒ #9416

@noygafni

Description

@noygafni

πŸ“œ Description

I am migrating my application from using Typebox schemas to Zod schemas, and encountered an issue with zod4 and novu.
When defining a workflow with a payloadSchema built using Zod v4, TypeScript does not infer the payload type. Inside step.* handlers, payload properties are typed as never (e.g., Property 'foo' does not exist on type 'never').
The same code path does infer correctly when the schema is defined with TypeBox.
The versions:
"zod-to-json-schema": "~3.24.6",
"zod": "4.1.12",
"@novu/framework": "^2.7.1"

πŸ‘Ÿ Reproduction steps

import { workflow } from '@novu/framework';
import { z } from 'zod';

const payloadSchema = z.object({
  applicationUrl: z.string().url(),
  opportunityId: z.string(),
  status: z.enum(['pending', 'approved', 'rejected']),
});

export const myWorkflow = workflow(
  'MY_WORKFLOW',
  async ({ payload, step }) => {
    // TypeScript error here:
    // Property 'applicationUrl' does not exist on type 'never'.
    await step.email('send-email', async () => {
      return {
        subject: `Status: ${payload.status}`, // ts error: Property 'status' does not exist on type 'never'.
        body: `Open: ${payload.applicationUrl}`, // ts error: Property 'applicationUrl' does not exist on type 'never'.
      };
    });

    await step.inApp('notify', async () => {
      return {
        subject: 'Update',
        body: `Changed to ${payload.status}`,
        data: { opportunityId: payload.opportunityId }, // flagged as never
      };
    });
  },
  {
    payloadSchema, // <- Zod schema provided here
    tags: ['example'],
  }
);

πŸ‘ Expected behavior

The types will be inferred correctly as the type of the zod schema.

πŸ‘Ž Actual Behavior with Screenshots

The types are not inferred and is considered as 'never'

Novu version

@novu/framework: 2.7.1

npm version

No response

node version

No response

πŸ“ƒ Provide any additional context for the Bug.

No response

πŸ‘€ Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find a similar issue

🏒 Have you read the Contributing Guidelines?

Are you willing to submit PR?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions