#Fastify cookies plagin can't expand Fastify types

14 messages · Page 1 of 1 (latest)

snow wedge
#

I want to use @fastify/cookies plugin, i setup like in docs, but my types still doesn't have types like setCookie, cookie etc.
I use nx monorepo and i want to use it in my library which expose modules to core app. Firstly i though that it's related with this architecture, but when i check in app (where I register plugin) i try to use it in app controller, it still doesn't work.

I use pnpm 8.6.7, nx integrated repos architecture (so there is one node_modules and package.json at root folder and all apps and libs use it)

import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import { AppModule } from './app/app.module';
import fastifyCookie from '@fastify/cookie';

const globalPrefix = 'api';

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter());

  await app.register(fastifyCookie, {
    secret:'COOKIES_SIGNATURE',
  });
  ...
}
bootstrap();

And in controller at the same app:

import { Controller, Get, Req, Res } from '@nestjs/common'
import { AppService } from './app.service'
import { FastifyReply, FastifyRequest } from 'fastify'
import fastifyCookie from '@fastify/cookie';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  test(@Req() request: FastifyRequest, @Res({ passthrough: true }) res: FastifyReply){
    request.cookies // Property 'setCookies' does not exist on type 'FastifyRequest<RouteGenericInterface, RawServerDefault, IncomingMessage, FastifySchema, FastifyTypeProviderDefault, unknown, FastifyBaseLogger, ResolveFastifyRequestType<...>>'.ts(2339)
    // res.
  }
}
#

I also try to include types in tsconfig but it also doesn't work :/

agile torrent
#

There's most likely two installed versions of fastify. One from @nestjs/platform-fastify Ave one installed directly. Make these two versions match and everything should work

snow wedge
#

Still not works. I have changed everything to the same versions, so @nestjs/platform-fastify use 4.19.2, and i instaled fastify 4.19.2 and i also changed the fastify version in @fastify/cookies package.json to the same.

agile torrent
#

Can you provide a minimum reproduction?

snow wedge
#

It can be hard to do, but I can give you access to my private repo

agile torrent
#

How hard is it to run?

snow wedge
#

Hmm, the logic and code works, but the typing doesn't. So I think simple package installation and you don't need to run it locally, am I right?

agile torrent
#

That's the hope

snow wedge
#

I gave you access

#

libs/core/src/lib/auth/auth.controller.ts#L19

agile torrent
#

What's the build command?

snow wedge
#

i haven't built this yet, but to get started is the nx serve api

agile torrent
#

Add import @fastify/cookie' and the types work