@@ -17,6 +17,8 @@ export * from './types';
17
17
export { default as HelmetData } from './HelmetData' ;
18
18
export { default as HelmetProvider } from './Provider' ;
19
19
20
+ type Props = { [ key : string ] : any } ;
21
+
20
22
export class Helmet extends Component < PropsWithChildren < HelmetProps > > {
21
23
static defaultProps = {
22
24
defer : true ,
@@ -52,10 +54,10 @@ export class Helmet extends Component<PropsWithChildren<HelmetProps>> {
52
54
}
53
55
54
56
flattenArrayTypeChildren (
55
- child : any ,
56
- arrayTypeChildren : any ,
57
- newChildProps : any ,
58
- nestedChildren : any
57
+ child : JSX . Element ,
58
+ arrayTypeChildren : { [ key : string ] : JSX . Element [ ] } ,
59
+ newChildProps : Props ,
60
+ nestedChildren : ReactNode
59
61
) {
60
62
return {
61
63
...arrayTypeChildren ,
@@ -69,7 +71,12 @@ export class Helmet extends Component<PropsWithChildren<HelmetProps>> {
69
71
} ;
70
72
}
71
73
72
- mapObjectTypeChildren ( child : any , newProps : any , newChildProps : any , nestedChildren : any ) {
74
+ mapObjectTypeChildren (
75
+ child : JSX . Element ,
76
+ newProps : Props ,
77
+ newChildProps : Props ,
78
+ nestedChildren : ReactNode
79
+ ) {
73
80
switch ( child . type ) {
74
81
case TAG_NAMES . TITLE :
75
82
return {
@@ -97,7 +104,7 @@ export class Helmet extends Component<PropsWithChildren<HelmetProps>> {
97
104
}
98
105
}
99
106
100
- mapArrayTypeChildrenToProps ( arrayTypeChildren : any , newProps : any ) {
107
+ mapArrayTypeChildrenToProps ( arrayTypeChildren : { [ key : string ] : JSX . Element } , newProps : Props ) {
101
108
let newFlattenedProps = { ...newProps } ;
102
109
103
110
Object . keys ( arrayTypeChildren ) . forEach ( arrayChildName => {
@@ -110,7 +117,7 @@ export class Helmet extends Component<PropsWithChildren<HelmetProps>> {
110
117
return newFlattenedProps ;
111
118
}
112
119
113
- warnOnInvalidChildren ( child : any , nestedChildren : any ) {
120
+ warnOnInvalidChildren ( child : JSX . Element , nestedChildren : ReactNode ) {
114
121
invariant (
115
122
VALID_TAG_NAMES . some ( name => child . type === name ) ,
116
123
typeof child . type === 'function'
@@ -133,24 +140,24 @@ export class Helmet extends Component<PropsWithChildren<HelmetProps>> {
133
140
return true ;
134
141
}
135
142
136
- mapChildrenToProps ( children : any , newProps : any ) {
143
+ mapChildrenToProps ( children : ReactNode , newProps : Props ) {
137
144
let arrayTypeChildren = { } ;
138
145
139
- React . Children . forEach ( children , child => {
146
+ React . Children . forEach ( children as JSX . Element , ( child : ReactElement ) => {
140
147
if ( ! child || ! child . props ) {
141
148
return ;
142
149
}
143
150
144
151
const { children : nestedChildren , ...childProps } = child . props ;
145
152
// convert React props to HTML attributes
146
- const newChildProps = Object . keys ( childProps ) . reduce ( ( obj : any , key ) => {
153
+ const newChildProps = Object . keys ( childProps ) . reduce ( ( obj : Props , key ) => {
147
154
obj [ HTML_TAG_MAP [ key ] || key ] = childProps [ key ] ;
148
155
return obj ;
149
156
} , { } ) ;
150
157
151
158
let { type } = child ;
152
159
if ( typeof type === 'symbol' ) {
153
- type = type . toString ( ) ;
160
+ type = ( type as 'symbol' ) . toString ( ) ;
154
161
} else {
155
162
this . warnOnInvalidChildren ( child , nestedChildren ) ;
156
163
}
0 commit comments