@@ -22,7 +22,7 @@ import { typedObjectKeys } from '../utils/typed-object-keys'
2222
2323const logger = new Logger ( 'FontAwesomeIcon' )
2424
25- const defaultProps = {
25+ const DEFAULT_PROPS = {
2626 border : false ,
2727 className : '' ,
2828 mask : undefined ,
@@ -53,6 +53,8 @@ const defaultProps = {
5353 widthAuto : false ,
5454}
5555
56+ const DEFAULT_PROP_KEYS = new Set ( Object . keys ( DEFAULT_PROPS ) )
57+
5658const EMPTY_OBJECT : Record < string , never > = { }
5759
5860export interface FontAwesomeIconProps
@@ -153,7 +155,7 @@ export const FontAwesomeIcon = React.forwardRef(
153155 props : FontAwesomeIconProps ,
154156 ref : React . Ref < SVGSVGElement > ,
155157 ) : React . JSX . Element | null => {
156- const allProps : FontAwesomeIconProps = { ...defaultProps , ...props }
158+ const allProps : FontAwesomeIconProps = { ...DEFAULT_PROPS , ...props }
157159
158160 const {
159161 icon : iconArgs ,
@@ -199,12 +201,14 @@ export const FontAwesomeIcon = React.forwardRef(
199201
200202 for ( const key of typedObjectKeys ( allProps ) ) {
201203 // Skip default props
202- if ( key in defaultProps ) {
204+ if ( DEFAULT_PROP_KEYS . has ( key ) ) {
203205 continue
204206 }
205207
206208 // Add all other props to the extraProps object
207- // @ts -expect-error TypeScript doesn't know that allProps[key] is valid
209+ // @ts -expect-error since `key` can be any of the keys in FontAwesomeIconProps,
210+ // TypeScript widens the type of the `obj[key]` lookups to a union of all possible values,
211+ // which will not correctly overlap each other.
208212 extraProps [ key ] = allProps [ key ]
209213 }
210214
0 commit comments