我想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)
提前谢谢你。
我有一个 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”的对象,但如果它有另一个具有相同属性但值不同的对象,则测试不会失败。
是否可以?在此之前,我一直使用静态索引,因为该数组中只有一个元素。