How to reduce javascript object to only contain properties from interface

后端 未结 7 1387
迷失自我
迷失自我 2020-12-06 04:29

When using typescript a declared interface could look like this:

interface MyInterface {
  test: string;
}

And an implementation with extra

7条回答
  •  情深已故
    2020-12-06 04:54

    TS 2.1 has Object Spread and Rest, so it is possible now:

    var my: MyTest = {test: "hello", newTest: "world"}
    
    var { test, ...reduced } = my;
    

    After that reduced will contain all properties except of "test".

提交回复
热议问题