#CanActivate observable type issue

1 messages · Page 1 of 1 (latest)

distant cove
#

wondering if anyone else has been having this issue? Restarting the TS server and running the app works but this is causing build errors and sometimes prevents server from running.

The inferred type of 'canActivate' cannot be named without a reference to '.pnpm/[email protected]/node_modules/rxjs'. This is likely not portable. A type annotation is necessary.

import {
  ExecutionContext,
  Injectable,
  InternalServerErrorException,
  Logger,
  UnauthorizedException,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Reflector } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport';
import { UserRole } from '@prisma/client';
import { verify } from 'jsonwebtoken';

@Injectable()
export class AtGuard extends AuthGuard('jwt') {
  constructor(
    private readonly reflector: Reflector,
    private readonly logger: Logger,
    private readonly config: ConfigService
  ) {
    super();
  }

  canActivate(context: ExecutionContext) {} // TS error occurs on this line
quick wing
#

Just explicitly set the type. Rxjs can't be transitively used here, kind of annoying, but not a huge deal

silk orchid
#

that is annoying - any fix with pnpm v8?

#

otherwise what should it be explicitly typed as?

quick wing
#

If you return an observable, use Observable<boolean>, if promise, Promise<boolean>, else boolean

silk orchid
#

thank you

silk orchid
#

when returning the super method after statically typing it, it complains

#

just change it to the same signature as super.canActivate()?

quick wing
#

What is the extends of?

silk orchid
#

AuthGuard('jwt') from @nestjs/passport

quick wing
#

That method is async

#

You need to use Promise<boolean>

silk orchid
#

it still throws a fit

quick wing
#

Then use as to tell Typescript it's fine