我有這個:
export class QueueEntity<T> implements HasInternalQueue<T> {
opts: { // <--- inline type here
foo: boolean
}
constructor(v: typeof this.opts) { // this doesn't quite work
this.opts = v
}
}
有沒有辦法參考行內型別或者這是不可能的?
uj5u.com熱心網友回復:
由于無法直接在類中定義型別(TS repo 中的一個未解決問題)。我認為您可以使用類名來參考this:
export class QueueEntity<T> {
opts: { // <--- inline type here
foo: boolean
}
constructor(v: QueueEntity<T>['opts']) { // <-- should work now
this.opts = v
}
}
const obj = new QueueEntity({ foo : false });
const obj2 = new QueueEntity({ foo2 : false });
const obj3 = new QueueEntity();
操場
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/530458.html
標籤:节点.js打字稿
