Skip to content

Commit 47ef56a

Browse files
committed
fix(ts): widens type for RawNodeDatum["attributes"] (#350)
`attributes` was made unintentionally restrictive during the v2 refactor to Typescript, by moving from a loose implicit `object` type to `Record<string, string>`. This commit widens the used `Record` type to additionally accept `number` and `boolean` primitives as possible values.
1 parent 4a7d21f commit 47ef56a

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ By default, `Tree` expects each node object in `data` to implement the [`RawNode
129129
```ts
130130
interface RawNodeDatum {
131131
name: string;
132-
attributes?: Record<string, string>;
132+
attributes?: Record<string, string | number | boolean>;
133133
children?: RawNodeDatum[];
134134
}
135135
```

src/Node/DefaultNodeElement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const DefaultNodeElement: React.FunctionComponent<DefaultNodeElementProps> = ({
4545
{nodeDatum.attributes &&
4646
Object.entries(nodeDatum.attributes).map(([labelKey, labelValue], i) => (
4747
<tspan key={`${labelKey}-${i}`} {...textLayout.attribute}>
48-
{labelKey}: {labelValue}
48+
{labelKey}: {typeof labelValue === 'boolean' ? labelValue.toString() : labelValue}
4949
</tspan>
5050
))}
5151
</text>

src/types/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface Point {
1010

1111
export interface RawNodeDatum {
1212
name: string;
13-
attributes?: Record<string, string>;
13+
attributes?: Record<string, string | number | boolean>;
1414
children?: RawNodeDatum[];
1515
}
1616

0 commit comments

Comments
 (0)