Is there a way to dynamically extract members from an object belonging to an interface (i.e. not specifying them again explicitly), like this:
let subset = { ...someObject as ISpecific };
Currently I get all members that someObject happens to have.
So the spread operator does not work here. Are there any ways to do that yet?
Example:
interface ISpecific { A: string; B: string; }
class Extended implements ISpecific { public A: string = '1'; public B: string = '2'; public C: string = '3'; }
let someObject = new Extended();
let subset = { ...someObject as ISpecific };
console.log(subset); // -> { A, B, C } but want { A, B }
TypeScript casts are merely hints for the compiler, not real conversions at runtime.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…