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