0
我有一些代码,看起来像这样简单的例子:对象属性的嵌套匹克
interface Foo {
x: string;
y: string;
}
interface Bar {
a: string;
b: number;
foo: Foo
}
function printStuff(bar: Bar) {
console.log(bar.a);
console.log(bar.foo.x);
}
在我的单元测试,我要要调用printStuff
与最低限度参数:{a: 'someval', foo: {x: 1}}
。我不想为Foo
和Bar
构建完整参数集的对象。
我知道我能写的printStuff
参数签名作为一个匿名接口,但随后的断开连接从发生到Foo
和Bar
任何变化。如果我使用参数中的更多属性,它可能会变得冗长。
我可以改为使用Pick
来定义我的函数的确切属性?
退房'Partial' 。 – 2017-04-16 09:19:21