小编Hie*_*enz的帖子

Typescript 基于接口从另一个对象创建一个对象

我想ExampleInterface从另一个对象创建一个对象,但只保留ExampleInterface包含的那些属性。

是否可以不手动复制每个密钥?

export interface ExampleInterface {
  property1: string;
  property2: string;
}
Run Code Online (Sandbox Code Playgroud)

进而

const exampleObject: ExampleInterface = anotherObjectThatHasMoreProperties;
Run Code Online (Sandbox Code Playgroud)

提前谢谢你。

typescript

7
推荐指数
1
解决办法
9558
查看次数

放心地在对象数组中查找特定的键值对

我有一个 json 响应,如下所示:

"someArray": [
    {
       "someProperty":"someValue",
       // other properties that are not relevant for me
    },
    {
       "someProperty":"someOtherValue",
       // other properties that are not relevant for me
    }
]
Run Code Online (Sandbox Code Playgroud)

我想检查 someArray 数组是否有一个名为“someProperty”的属性且值为“someValue”的对象,但如果它有另一个具有相同属性但值不同的对象,则测试不会失败。

是否可以?在此之前,我一直使用静态索引,因为该数组中只有一个元素。

java rest-assured rest-assured-jsonpath

2
推荐指数
1
解决办法
9230
查看次数