1
- import React from 'react'
2
-
3
- // statics handler
4
1
import hoistStatics from 'hoist-non-react-statics'
2
+ import React from 'react'
3
+ import { Subtract } from 'utility-types'
5
4
6
5
let language : string = 'pt'
7
6
let id : number = 1
@@ -20,7 +19,9 @@ export interface ITranslations {
20
19
[ key : string ] : ITranslation
21
20
}
22
21
23
- export type T = ( path : string , args ?: { [ key : string ] : string } ) => string
22
+ export interface ITranslate {
23
+ t ( path : string , args ?: { [ key : string ] : string } ) : string
24
+ }
24
25
25
26
let translations : ITranslations = { }
26
27
@@ -106,8 +107,10 @@ export function t(path: string, args?: {[key: string]: string}): string {
106
107
return translation
107
108
}
108
109
109
- export function translate ( Component : React . ComponentType < any > ) : React . ComponentType < any > {
110
- class TranslatedComponet extends React . Component < any , any > {
110
+ export function translate < P extends ITranslate > (
111
+ Component : React . ComponentType < P >
112
+ ) : React . ComponentType < Subtract < P , ITranslate > > {
113
+ class TranslatedComponent extends React . Component < Subtract < P , ITranslate > > {
111
114
public id : number | undefined
112
115
113
116
public componentDidMount ( ) {
@@ -121,11 +124,11 @@ export function translate(Component: React.ComponentType<any>): React.ComponentT
121
124
}
122
125
123
126
public render ( ) {
124
- return < Component { ...this . props } t = { t } />
127
+ return < Component { ...this . props as P } t = { t } />
125
128
}
126
129
}
127
130
128
- return hoistStatics ( TranslatedComponet , Component )
131
+ return hoistStatics ( TranslatedComponent , Component )
129
132
}
130
133
131
134
export default {
0 commit comments