简体   繁体   中英

What are the arguments in the parent class of an inheritance in Typescript?

In an example I've found in a documentation, it seems like certain inheritance in Typescript can have additional arguments to the parent class of an inheritance. I'm not sure if this is a new feature in Typescript.

For example:

export class HttpStrategy extends PassportStrategy(Strategy, 'google') {
  constructor(private readonly authService: AuthService) {

In this case, the parent class PassportStrategy is able to take in an argument. However, that doesn't seem like an argument that will be passed to PassportStrategy's constructor because it would have been passed through super() if that was the case.

So, then, what are those arguments and where are the arguments of the parent class in a Typescript inheritance being used?

PS: I've tried to search online for its documentation but I think I'm not looking with the right keyword of such arguments.

What you provide in the extends clause can be any expression, so what's happening there is that a function called PassportStrategy is getting called with those two arguments and then HttpStrategy extends the class it returns , like this:

 function Base(arg) { return class { doSomething() { console.log("something: ", arg); } }; } class Sub1 extends Base(1) { } const s1 = new Sub1(); s1.doSomething(); class Sub2 extends Base(2) { } const s2 = new Sub2(); s2.doSomething(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM