Skip to content

Commit b6b1004

Browse files
Merge pull request #245 from remarkablemark/fix/types
fix(attributes-to-props): fix attributes-to-props type `Props`
2 parents 0ed9598 + c9c3b02 commit b6b1004

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/attributes-to-props.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// TypeScript Version: 4.1
22

33
export type Attributes = Record<string, string>;
4-
export type Props = Attributes;
4+
5+
export type Props = Record<string, string> & {
6+
style: Record<string, string>;
7+
};
58

69
/**
710
* Converts HTML/SVG DOM attributes to React props.

test/types/lib/attributes-to-props.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import attributesToProps, {
2+
Attributes,
3+
Props
4+
} from 'html-react-parser/lib/attributes-to-props';
5+
6+
let attributes: Attributes = {};
7+
8+
attributes = {
9+
class: 'my-class',
10+
style: 'color: #bada55; line-height: 42;'
11+
};
12+
13+
// $ExpectType Props
14+
const {
15+
className,
16+
style: { color, lineHeight }
17+
} = attributesToProps(attributes);

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"index.d.ts",
2121
"lib/dom-to-react.d.ts",
2222
"test/types/index.tsx",
23+
"test/types/lib/attributes-to-props.ts",
2324
"test/types/lib/dom-to-react.tsx"
2425
]
2526
}

0 commit comments

Comments
 (0)