Skip to content

Wrong type resolution - a non optional type resolved as optional #259

@vokrik

Description

@vokrik

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.6.1

Plugin version

6.1.0

Node.js version

24.0.2

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

15.7.1

Description

I have this code that works perfectly fine in 5.2.0

import { type FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
import { Type } from '@sinclair/typebox';

export const ExecutionIdSchema = Type.String({
	format: 'uuid',
});
export const executionController: FastifyPluginAsyncTypebox = async (app) => {
	app.post(
		'/v1/workflows/run',
		{
			schema: {
				body: Type.Object({
					executionId: ExecutionIdSchema,
				}),
				consumes: ['application/json'],
			},
		},
		async (request) => {
			const log = request.log.child({ executionId: request.body.executionId });

			const executionId = request.body.executionId; // <-- type of the executionId is string
		},
	);
};

When I upgrade to 6.1.0 (and 6.0.0), the executionId is typed as string | undefined

Link to code that reproduces the bug

fastify/fastify#3617 (comment)

Expected Behavior

The type of the executionId is string (it's not marked as Type.Optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions