@@ -9,16 +9,16 @@ import {
9
9
} from './utils' ;
10
10
11
11
type PropTypes = { [ key : string ] : any } ;
12
- interface PropTypeValidator {
12
+ type PropTypeValidator = {
13
13
< P extends PropTypes > (
14
14
props : P ,
15
15
propName : string & keyof P ,
16
16
componentName : string ,
17
17
) : null | Error ;
18
- }
19
- interface PropTypeWithRequired extends PropTypeValidator {
18
+ } ;
19
+ type PropTypeWithRequired = PropTypeValidator & {
20
20
isRequired : PropTypeValidator ;
21
- }
21
+ } ;
22
22
23
23
function createPropType < P extends PropTypes > (
24
24
validator : PropTypeValidator ,
@@ -51,11 +51,12 @@ const vec2ObjValidator = <P extends PropTypes>(
51
51
: new Error ( `${ propName } in ${ componentName } is not a vec2 shape` ) ;
52
52
} ;
53
53
54
- export const vec2Obj : PropTypeWithRequired = createPropType (
55
- vec2ObjValidator ,
56
- false ,
57
- ) as PropTypeWithRequired ;
58
- vec2Obj . isRequired = createPropType ( vec2ObjValidator , true ) ;
54
+ export const vec2Obj : PropTypeWithRequired = Object . assign (
55
+ createPropType ( vec2ObjValidator , false ) ,
56
+ {
57
+ isRequired : createPropType ( vec2ObjValidator , true ) ,
58
+ } ,
59
+ ) ;
59
60
60
61
const vec3ObjValidator = < P extends PropTypes > (
61
62
props : P ,
@@ -68,11 +69,10 @@ const vec3ObjValidator = <P extends PropTypes>(
68
69
: new Error ( `${ propName } in ${ componentName } is not a vec3 shape` ) ;
69
70
} ;
70
71
71
- export const vec3Obj : PropTypeWithRequired = createPropType (
72
- vec3ObjValidator ,
73
- false ,
74
- ) as PropTypeWithRequired ;
75
- vec3Obj . isRequired = createPropType ( vec3ObjValidator , true ) ;
72
+ export const vec3Obj : PropTypeWithRequired = Object . assign (
73
+ createPropType ( vec3ObjValidator , false ) ,
74
+ { isRequired : createPropType ( vec3ObjValidator , true ) } ,
75
+ ) ;
76
76
77
77
const vec2GlMatrixValidator = < P extends PropTypes > (
78
78
props : P ,
@@ -85,11 +85,12 @@ const vec2GlMatrixValidator = <P extends PropTypes>(
85
85
: new Error ( `${ propName } in ${ componentName } is not a gl-matrix vec2` ) ;
86
86
} ;
87
87
88
- export const vec2GlMatrix : PropTypeWithRequired = createPropType (
89
- vec2GlMatrixValidator ,
90
- false ,
91
- ) as PropTypeWithRequired ;
92
- vec2GlMatrix . isRequired = createPropType ( vec2GlMatrixValidator , true ) ;
88
+ export const vec2GlMatrix : PropTypeWithRequired = Object . assign (
89
+ createPropType ( vec2GlMatrixValidator , false ) ,
90
+ {
91
+ isRequired : createPropType ( vec2GlMatrixValidator , true ) ,
92
+ } ,
93
+ ) ;
93
94
94
95
const vec3GlMatrixValidator = < P extends PropTypes > (
95
96
props : P ,
@@ -101,11 +102,12 @@ const vec3GlMatrixValidator = <P extends PropTypes>(
101
102
? null
102
103
: new Error ( `${ propName } in ${ componentName } is not a gl-matrix vec3` ) ;
103
104
} ;
104
- export const vec3GlMatrix : PropTypeWithRequired = createPropType (
105
- vec3GlMatrixValidator ,
106
- false ,
107
- ) as PropTypeWithRequired ;
108
- vec3GlMatrix . isRequired = createPropType ( vec3GlMatrixValidator , true ) ;
105
+ export const vec3GlMatrix : PropTypeWithRequired = Object . assign (
106
+ createPropType ( vec3GlMatrixValidator , false ) ,
107
+ {
108
+ isRequired : createPropType ( vec3GlMatrixValidator , true ) ,
109
+ } ,
110
+ ) ;
109
111
110
112
const mat2dGlMatrixValidator = < P extends PropTypes > (
111
113
props : P ,
@@ -118,11 +120,10 @@ const mat2dGlMatrixValidator = <P extends PropTypes>(
118
120
: new Error ( `${ propName } in ${ componentName } is not a gl-matrix mat2d` ) ;
119
121
} ;
120
122
121
- export const mat2dGlMatrix : PropTypeWithRequired = createPropType (
122
- mat2dGlMatrixValidator ,
123
- false ,
124
- ) as PropTypeWithRequired ;
125
- mat2dGlMatrix . isRequired = createPropType ( mat2dGlMatrixValidator , true ) ;
123
+ export const mat2dGlMatrix : PropTypeWithRequired = Object . assign (
124
+ createPropType ( mat2dGlMatrixValidator , false ) ,
125
+ { isRequired : createPropType ( mat2dGlMatrixValidator , true ) } ,
126
+ ) ;
126
127
127
128
export const mat4GlMatrixValidator = < P extends PropTypes > (
128
129
props : P ,
@@ -135,8 +136,7 @@ export const mat4GlMatrixValidator = <P extends PropTypes>(
135
136
: new Error ( `${ propName } in ${ componentName } is not a gl-matrix mat4` ) ;
136
137
} ;
137
138
138
- export const mat4GlMatrix : PropTypeWithRequired = createPropType (
139
- mat4GlMatrixValidator ,
140
- false ,
141
- ) as PropTypeWithRequired ;
142
- mat4GlMatrix . isRequired = createPropType ( mat4GlMatrixValidator , true ) ;
139
+ export const mat4GlMatrix : PropTypeWithRequired = Object . assign (
140
+ createPropType ( mat4GlMatrixValidator , false ) ,
141
+ { isRequired : createPropType ( mat4GlMatrixValidator , true ) } ,
142
+ ) ;
0 commit comments