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

Bad typings for Fastify server enableCors method, delegator property is missing #13234

Closed
3 of 15 tasks
mdorda opened this issue Feb 20, 2024 · 3 comments · May be fixed by #13247
Closed
3 of 15 tasks

Bad typings for Fastify server enableCors method, delegator property is missing #13234

mdorda opened this issue Feb 20, 2024 · 3 comments · May be fixed by #13247
Labels
needs triage This issue has not been looked into

Comments

@mdorda
Copy link

mdorda commented Feb 20, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When passing delegator property to enableCors method (according to @fastify/cors documentation), it issues:

Object literal may only specify known properties, and 'delegator' does not exist in type 'CorsOptions | CorsOptionsDelegate<any>'

It is needed to access the whole request object. Using cors property or pass function (CorsOptionsDelegate<T>) allows to access only origin string property and whole fastify object, but not the request itself.

Minimum reproduction code

https://github.com

Steps to reproduce

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

app.enableCors({
    // this issues an TS error, but works in runtime as expected
    delegator: (request: FastifyRequest, callback: CorsOptionsCallback): void => {
        //
    },
});

Expected behavior

Code provided in "Steps to reproduce" should not issues an TS error.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

10.3.1

Packages versions

"@fastify/compress": "~6.5.0",
"@fastify/static": "~6.12.0",
"@nestjs/cli": "~10.3.0",
"@nestjs/common": "~10.3.1",
"@nestjs/core": "~10.3.1",
"@nestjs/passport": "~10.0.3",
"@nestjs/platform-fastify": "~10.3.1",
"@nestjs/schedule": "^4.0.0",
"@nestjs/swagger": "~7.2.0",

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@mdorda mdorda added the needs triage This issue has not been looked into label Feb 20, 2024
@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@mdorda
Copy link
Author

mdorda commented Feb 21, 2024

If it is desirable to fix the issue, I will be happy to do so.

mdorda pushed a commit to mdorda/nest that referenced this issue Feb 22, 2024
Fastify adapter uses typings from `@fastify/cors` package for `enableCors` method

Fix nestjs#13234
@kamilmysliwiec
Copy link
Member

Let's track this here #13247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants