Skip to content

Release 3.1.0 broke type inference on fastify route handler request parameter #73

@g0di

Description

@g0di

Prerequisites

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

Fastify version

4.15.0

Plugin version

3.1.0

Node.js version

16.19.1

Operating system

macOS

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

Monterey 12.6.5

Description

Hi,

Just updated plugin to version 3.1.0 recently and it looks like I lost types inference on the fastify routes handler request object. I rollbacked to 3.0.0 which is working fine. The following screenshot is showing that I no longer get types inference on the params object of the fastify request despite schema definition being provided and Typebox type provider being used.

image

Thank you for your help ;)

Steps to Reproduce

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

fastify()
  .withTypeProvider<TypeBoxTypeProvider>()
  .get('/', {
    schema: {
      params: Type.Object({
        foo: Type.String()
      })
    },
    handler(req, rep) {
      console.log(req.params.foo);
      rep.send();
    }
  });

Expected Behavior

  • In the previous example, req.params.foo should be typed as a string.
  • Using strict flag with typescript, I should not get the following error:
'req.params' is of type 'unknown'.ts(18046)

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