[英]What are the arguments in the parent class of an inheritance in Typescript?
在我在文檔中找到的一個示例中,似乎Typescript中的某些繼承可以為繼承的父類添加其他參數。 我不確定這是否是Typescript中的新功能。
例如:
export class HttpStrategy extends PassportStrategy(Strategy, 'google') {
constructor(private readonly authService: AuthService) {
在這種情況下,父類PassportStrategy可以接受參數。 但是,這似乎不像將傳遞給PassportStrategy的構造函數的參數,因為如果是這種情況,它將通過super()傳遞。
那么,這些參數是什么?在Typescript繼承中使用的父類的參數在哪里?
PS:我試圖在網上搜索其文檔,但我認為我沒有在尋找此類參數的正確關鍵字。
你在提供extends
條款可以是任何的表情,所以發生的事情有一種叫做功能 PassportStrategy
獲取調用與這兩個參數,然后HttpStrategy
擴展它返回類,就像這樣:
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.