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

bugfix(@nestjs/passport) return correct type from PassportStragegy #126

Closed

Conversation

mleguen
Copy link

@mleguen mleguen commented Oct 2, 2019

Type the return value of PassportStrategy() as a Strategy instead of a 'typeof Strategy'

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

import { Strategy } from 'passport-saml';
import { PassportStrategy } from '@nestjs/passport';

export class SamlStrategy extends PassportStrategy(Strategy) {
  // [...]
  generateServiceProviderMetadata(): string {
    // type error: super has type "typeof Strategy" which has no generateServiceProviderMetadata member
    return super.generateServiceProviderMetadata(...);
  }
}

What is the new behavior?

import { Strategy } from 'passport-saml';
import { PassportStrategy } from '@nestjs/passport';

export class SamlStrategy extends PassportStrategy(Strategy) {
  // [...]
  generateServiceProviderMetadata(): string {
    // OK: super has type "Strategy" which has a generateServiceProviderMetadata member
    return super.generateServiceProviderMetadata(...);
  }
}

Does this PR introduce a breaking change?

[ ] Yes
[X] No

Other information

Type the return value as a Strategy instead of a 'typeof Strategy'

export function PassportStrategy<T extends Type<any> = any>(
Strategy: T,
name?: string | undefined
): {
new (...args): T;
new (...args): Value<T>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we change this line:

Strategy: T,

instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean Strategy: Type<T> and T extends any? That was my first try and it did not work.

@kamilmysliwiec
Copy link
Member

Fixed here #134

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

Successfully merging this pull request may close these issues.

2 participants