2
在D3中,通常爲已有的D3變量添加屬性。如何擴展和界面已設置類型?
一個例子(ES5):
force = d3.layout.force()
.nodes([{ links: 0, color: '#2BC9E9' }])
錯誤:
Argument of type '{ links: number; color: string; }[]' is not assignable to
parameter of type 'Node[]'.
如果我們能夠創建一個新的界面,我們會簡單做:
interface Node_ extends Node {
links: number;
color: string;
}
如何擴展在D3的類型中已經定義了接口Node
以允許新的屬性?