Skip to content

Commit

Permalink
Merge pull request #245 from remarkablemark/fix/types
Browse files Browse the repository at this point in the history
fix(attributes-to-props): fix attributes-to-props type `Props`
  • Loading branch information
remarkablemark committed Apr 18, 2021
2 parents 0ed9598 + c9c3b02 commit b6b1004
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/attributes-to-props.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// TypeScript Version: 4.1

export type Attributes = Record<string, string>;
export type Props = Attributes;

export type Props = Record<string, string> & {
style: Record<string, string>;
};

/**
* Converts HTML/SVG DOM attributes to React props.
Expand Down
17 changes: 17 additions & 0 deletions test/types/lib/attributes-to-props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import attributesToProps, {
Attributes,
Props
} from 'html-react-parser/lib/attributes-to-props';

let attributes: Attributes = {};

attributes = {
class: 'my-class',
style: 'color: #bada55; line-height: 42;'
};

// $ExpectType Props
const {
className,
style: { color, lineHeight }
} = attributesToProps(attributes);
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"index.d.ts",
"lib/dom-to-react.d.ts",
"test/types/index.tsx",
"test/types/lib/attributes-to-props.ts",
"test/types/lib/dom-to-react.tsx"
]
}

0 comments on commit b6b1004

Please sign in to comment.