Skip to content

Commit

Permalink
fix(ts): widens type for RawNodeDatum["attributes"] (#350)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
bkrem committed Jun 23, 2021
1 parent 4a7d21f commit 47ef56a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ By default, `Tree` expects each node object in `data` to implement the [`RawNode
```ts
interface RawNodeDatum {
name: string;
attributes?: Record<string, string>;
attributes?: Record<string, string | number | boolean>;
children?: RawNodeDatum[];
}
```
Expand Down
2 changes: 1 addition & 1 deletion src/Node/DefaultNodeElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const DefaultNodeElement: React.FunctionComponent<DefaultNodeElementProps> = ({
{nodeDatum.attributes &&
Object.entries(nodeDatum.attributes).map(([labelKey, labelValue], i) => (
<tspan key={`${labelKey}-${i}`} {...textLayout.attribute}>
{labelKey}: {labelValue}
{labelKey}: {typeof labelValue === 'boolean' ? labelValue.toString() : labelValue}
</tspan>
))}
</text>
Expand Down
2 changes: 1 addition & 1 deletion src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Point {

export interface RawNodeDatum {
name: string;
attributes?: Record<string, string>;
attributes?: Record<string, string | number | boolean>;
children?: RawNodeDatum[];
}

Expand Down

0 comments on commit 47ef56a

Please sign in to comment.