0
class base {
a: number;
b: number;
}
class child extends base {
c: number;
}
let obj: child = { a: 4, b: 5, c: 6 };
let test: base = obj as base;
console.log(test);
威爾輸出{A:4,B:5,C:6}Tyepscript鑄造對象的父對象
如何輸出{A:4,B:5}?
我看到的清楚,編譯後屬性定義也會消失,所以沒辦法使用hasOwnProperty ...如果類屬性更改,我想找到一個通用的方法。隨着刪除,我將不得不將代碼更改爲不同的地方。能夠僅改變班級結構將是一件好事。 : - / – Alexandre