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

fix inherited constructor params types #1439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dominikjasek
Copy link

@dominikjasek dominikjasek commented Oct 2, 2023

PR Checklist

PR Type

What kind of change does this PR introduce?

  • type safety improvement

What is the current behavior?

  • missing type safety

What is the new behavior?

  • stronger type safety

Does this PR introduce a breaking change?

  • Yes

It requires developer to really implement validate method as mentioned here. previously, you could pass it to super() by providing verify argument.

That means, previously, this was valid code:

@Injectable()
export class EcmsApiKeyStrategy extends PassportStrategy(HeaderAPIKeyStrategy, "api-key") {
    constructor() {
        super(
            { header: 'Authorization', prefix: 'Api-Key ' },
            true,
            (apikey: string, done: (...args: unknown[]) => void) => {
                return done(null, apikey === "some-random-token");
            },
        );
    }
}

but after this PR, I have to write:

@Injectable()
export class EcmsApiKeyStrategy extends PassportStrategy(HeaderAPIKeyStrategy, "api-key") {
    constructor() {
        super(
            { header: 'Authorization', prefix: 'Api-Key ' },
            true,
        );
    }

  validate(request: Request, payload: any) => {
      // here I will implement the logic
  }
}

@dominikjasek dominikjasek force-pushed the fix-inheritance-type branch 3 times, most recently from dbb87a1 to acb25c8 Compare October 2, 2023 20:45
@dominikjasek dominikjasek marked this pull request as ready for review October 2, 2023 20:45
@dominikjasek dominikjasek force-pushed the fix-inheritance-type branch 3 times, most recently from 546fe1d to 08a289a Compare October 3, 2023 05:13
@przemyslawwalczak
Copy link

that would be awesome! 🙏 cc @kamilmysliwiec

@kamilmysliwiec
Copy link
Member

Great PR! Since it introduces a minor breaking change, we'll have to wait to merge it until the next major release.

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

Successfully merging this pull request may close these issues.

How about changing the constructor parameter type of PassportStrategy like this?
3 participants