Skip to content

Commit 5f12cc1

Browse files
committed
fix weird TS error
1 parent 73669c7 commit 5f12cc1

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/propTypes.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import {
99
} from './utils';
1010

1111
type PropTypes = { [key: string]: any };
12-
interface PropTypeValidator {
12+
type PropTypeValidator = {
1313
<P extends PropTypes>(
1414
props: P,
1515
propName: string & keyof P,
1616
componentName: string,
1717
): null | Error;
18-
}
19-
interface PropTypeWithRequired extends PropTypeValidator {
18+
};
19+
type PropTypeWithRequired = PropTypeValidator & {
2020
isRequired: PropTypeValidator;
21-
}
21+
};
2222

2323
function createPropType<P extends PropTypes>(
2424
validator: PropTypeValidator,
@@ -51,11 +51,12 @@ const vec2ObjValidator = <P extends PropTypes>(
5151
: new Error(`${propName} in ${componentName} is not a vec2 shape`);
5252
};
5353

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+
);
5960

6061
const vec3ObjValidator = <P extends PropTypes>(
6162
props: P,
@@ -68,11 +69,10 @@ const vec3ObjValidator = <P extends PropTypes>(
6869
: new Error(`${propName} in ${componentName} is not a vec3 shape`);
6970
};
7071

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+
);
7676

7777
const vec2GlMatrixValidator = <P extends PropTypes>(
7878
props: P,
@@ -85,11 +85,12 @@ const vec2GlMatrixValidator = <P extends PropTypes>(
8585
: new Error(`${propName} in ${componentName} is not a gl-matrix vec2`);
8686
};
8787

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+
);
9394

9495
const vec3GlMatrixValidator = <P extends PropTypes>(
9596
props: P,
@@ -101,11 +102,12 @@ const vec3GlMatrixValidator = <P extends PropTypes>(
101102
? null
102103
: new Error(`${propName} in ${componentName} is not a gl-matrix vec3`);
103104
};
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+
);
109111

110112
const mat2dGlMatrixValidator = <P extends PropTypes>(
111113
props: P,
@@ -118,11 +120,10 @@ const mat2dGlMatrixValidator = <P extends PropTypes>(
118120
: new Error(`${propName} in ${componentName} is not a gl-matrix mat2d`);
119121
};
120122

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+
);
126127

127128
export const mat4GlMatrixValidator = <P extends PropTypes>(
128129
props: P,
@@ -135,8 +136,7 @@ export const mat4GlMatrixValidator = <P extends PropTypes>(
135136
: new Error(`${propName} in ${componentName} is not a gl-matrix mat4`);
136137
};
137138

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

Comments
 (0)