gpt4 book ai didi

typescript - 类型错误 : Class constructor MixinStrategy cannot be invoked without 'new'

转载 作者:搜寻专家 更新时间:2023-10-30 20:59:46 25 4
gpt4 key购买 nike

我正在关注这里的 jwt 示例 https://docs.nestjs.com/techniques/authentication .我复制并粘贴了示例。在 npm 安装必要的位和 bops 之后,我得到了这个错误,这在我刚刚复制的示例中没有发生。我不知道这是什么意思!有人有什么想法吗?

TypeError: Class constructor MixinStrategy cannot be invoked without 'new'

8 | export class JwtStrategy extends PassportStrategy(Strategy) {
9 | constructor(private readonly authService: AuthService) {
> 10 | super({
11 | jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
12 | secretOrKey: 'secretKey',
13 | });

at new JwtStrategy (data/auth/strategies/jwt.strategy.ts:10:5)
at resolveConstructorParams (../node_modules/@nestjs/core/injector/injector.js:64:84)
at Injector.resolveConstructorParams (../node_modules/@nestjs/core/injector/injector.js:86:30)

最佳答案

project缺少 @types/passport-jwt 类型,因此应该另外安装它们:

npm i -D @types/passport-jwt

这导致

src\auth\jwt.strategy.ts (10,6): Call target does not contain any signatures. (2346)

错误,因为 @nestjs/passport 没有正确输入; PassportStrategy return type is any .

为了解决这个问题,

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
...

应该改为:

import { ExtractJwt, Strategy } from 'passport-jwt';
import { AbstractStrategy, PassportStrategy } from '@nestjs/passport';
...
const PassportJwtStrategy: new(...args) => AbstractStrategy & Strategy = PassportStrategy(Strategy);

@Injectable()
export class JwtStrategy extends PassportJwtStrategy {
...

关于typescript - 类型错误 : Class constructor MixinStrategy cannot be invoked without 'new' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50654877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com