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

How about changing the constructor parameter type of PassportStrategy like this? #1072

Closed
1 task done
rojiwon0325 opened this issue Oct 27, 2022 · 1 comment · May be fixed by #1439
Closed
1 task done

How about changing the constructor parameter type of PassportStrategy like this? #1072

rojiwon0325 opened this issue Oct 27, 2022 · 1 comment · May be fixed by #1439

Comments

@rojiwon0325
Copy link

rojiwon0325 commented Oct 27, 2022

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

If i used PassportStrategy as LocalStrategy, FacebookStrtegy....,
I can't use typesystem like autocomplete by ts in super();

export class LocalStrategy extends PassportStrategys(Strategy) {
  constructor(private authService: AuthService) {
    super(); // ts system not work!
  }
}
// in passport.strategy.d.ts
import { Type } from '../interfaces';
export declare function PassportStrategy<T extends Type<any> = any>(Strategy: T, name?: string | undefined): {
    new (...args: any[]): InstanceType<T>; // any is sad
};

Describe the solution you'd like

It can use typesystem!

export declare function PassportStrategy<T extends Type<any> = any>(
  Strategy: T,
  name?: string, // undefined type is unnecessary
): { new (...args: ConstructorParameters<T>): InstanceType<T> };
// ConstructorParameters<> is Typescript default UtilityType 

link: https://www.typescriptlang.org/docs/handbook/utility-types.html#constructorparameterstype

Teachability, documentation, adoption, migration strategy

we can just use same code but can use autocomplete, type check, prefix.......

What is the motivation / use case for changing the behavior?

  1. I don't like "any type".
  2. If i use Strategy, I have to check Strategy constructor parameter type in strategy.d.ts.
  3. If i write wrong parameter, I can check immediately.
@rojiwon0325
Copy link
Author

rojiwon0325 commented Oct 27, 2022

but this solution have another problem.

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 a pull request may close this issue.

1 participant