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

v10 does not allow typing on custom getRequest method in class with extended AuthGuard #1413

Closed
2 tasks done
kpervin opened this issue Sep 8, 2023 · 1 comment
Closed
2 tasks done

Comments

@kpervin
Copy link

kpervin commented Sep 8, 2023

Did you read the migration guide?

  • I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Potential Commit/PR that introduced the regression

No response

Versions

9.0.3 -> 10.0.1

Describe the regression

Previously, there was no typing for getRequest on the AuthGuard class in 9.0.3. However, in 10.0.1, typing was introduced. The typing introduced conflicts with the ability to get the req variable from a GraphQL request when "noImplicitReturns": true is set in tsconfig.json. The only way that I have found to get rid of the error is to introduce @ts-expect-error or @ts-ignore. As such, I cannot use the code used in the Passport example in the NestJS docs.

Minimum reproduction code

import { IncomingMessage } from "http";
import { GqlExecutionContext } from "@nestjs/graphql";

/**
 * Global [guard](https://docs.nestjs.com/guards) for GraphQL requests.
 *
 * @see https://docs.nestjs.com/recipes/passport#graphql
 */
@Injectable()
export class GqlAuthGuard extends AuthGuard([
 ...
]) {  
  getRequest(context: ExecutionContext): IncomingMessage {
    const ctx = GqlExecutionContext.create(context);
    return ctx.getContext<{ req: IncomingMessage }>().req;
  }
  ...
}

Expected behavior

Allow the ability to type the getRequest method without errors thrown.

Other

The error thrown with the above example is as follows:

TS2416: Property  getRequest  in type  GqlAuthGuard  is not assignable to the same property in base type  IAuthGuard 
Type
(context: ExecutionContext) => IncomingMessage
is not assignable to type  <T = any>(context: ExecutionContext) => T 
Type  IncomingMessage  is not assignable to type  T 
 T  could be instantiated with an arbitrary type which could be unrelated to  IncomingMessage
@kamilmysliwiec
Copy link
Member

Fixed in 10.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants