Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript error: Property 'url' does not exist on type 'FastifyContextConfig'. #4788

Closed
2 tasks done
pkyeck opened this issue Jun 5, 2023 · 5 comments
Closed
2 tasks done
Labels
good first issue Good for newcomers missing types PR that does not implement TypeScript changes

Comments

@pkyeck
Copy link

pkyeck commented Jun 5, 2023

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.17.0

Plugin version

No response

Node.js version

18

Operating system

macOS

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

13.3.1

Description

I'm using TypeScript and when I try to access the request's routeConfig.url TS complains about url not existing.

Looking at the types for FastifyContextConfig finds an empty interface ... is this correct? Do I have to set this manually although the url and method are built-in attributes?

Steps to Reproduce

import Fastify, {
  FastifyRequest,
  FastifySchema,
  FastifyTypeProviderDefault,
  RawRequestDefaultExpression,
  RawServerDefault,
  RouteGenericInterface,
} from "fastify";

const fastify = Fastify({
  logger: false,
});

// TS is complaining about unknown url
fastify.addHook("onRequest", async function onRequest(req) {
  console.log(req.routeConfig.url);
});

// this works :( but I don't want to be the one telling fastify about their built-in attributes
fastify.addHook(
  "onRequest",
  async function onRequest(
    req: FastifyRequest<
      RouteGenericInterface,
      RawServerDefault,
      RawRequestDefaultExpression<RawServerDefault>,
      FastifySchema,
      FastifyTypeProviderDefault,
      { url: string }
    >
  ) {
    console.log(req.routeConfig.url);
  }
);

like to codesandbox: https://codesandbox.io/p/sandbox/fastify-routeconfig-url-xndp24

Expected Behavior

// in this case req.routeConfig should know about the url attribute 
fastify.addHook("onRequest", async function onRequest(req) {
  console.log(req.routeConfig.url);
});
@mcollina
Copy link
Member

I think we never populated FastifyContextConfig with all the relevant data because this is something like an internal data structure. However, I think it's about time. Would you like to send a PR?

@mcollina mcollina added good first issue Good for newcomers missing types PR that does not implement TypeScript changes labels Jun 10, 2023
dancastillo added a commit to dancastillo/fastify that referenced this issue Jun 24, 2023
@gimnathperera
Copy link

Hi @mcollina assign this to me

@pkyeck
Copy link
Author

pkyeck commented Jul 3, 2023

@climba03003 why did you close this? the two mentioned PRs weren't merged

@climba03003
Copy link
Member

@pkyeck
See #4850

@pkyeck
Copy link
Author

pkyeck commented Jul 3, 2023

ah nice, didn't see that PR only the external commit. thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers missing types PR that does not implement TypeScript changes
Projects
None yet
4 participants