@@ -107,13 +107,21 @@ export const typify = (
107
107
return arrayType ;
108
108
}
109
109
110
- if ( ! type ) return 'any' ;
110
+ if ( ! type )
111
+ throw new Error ( 'Missing type provided to typify, something is wrong in the documentation' ) ;
111
112
112
113
let innerTypes : TypeInformation [ ] | undefined ;
113
114
let typeAsString : string | TypeInformation | TypeInformation [ ] = type ;
114
115
115
116
if ( typeof type === 'object' ) {
116
- let newType = type . type || 'any' ;
117
+ if ( ! type . type ) {
118
+ console . error ( type ) ;
119
+ throw new Error (
120
+ 'Missing type property on object provided to typify, something is wrong in the documentation' ,
121
+ ) ;
122
+ }
123
+
124
+ let newType = type . type ;
117
125
118
126
if ( typeof newType === 'string' && newType . toLowerCase ( ) === 'string' ) {
119
127
const stringType = type as DetailedStringType ;
@@ -167,21 +175,19 @@ export const typify = (
167
175
return 'number[]' ;
168
176
case 'array' : {
169
177
if ( innerTypes ) return `Array<${ typify ( innerTypes [ 0 ] ) } >` ;
170
- debug ( chalk . yellow ( 'Untyped "Array" as return type' ) ) ;
171
- return 'any[]' ;
178
+ throw new Error ( 'Untyped "Array" as return type' ) ;
172
179
}
173
180
case 'true' :
174
181
case 'false' :
175
- debug ( chalk . cyan ( '"true" or "false" provided as return value, inferring "Boolean" type' ) ) ;
176
- return 'boolean' ;
182
+ throw new Error ( '"true" or "false" provided as return value, inferring "Boolean" type' ) ;
177
183
case '[objects]' :
178
- debug (
179
- chalk . red ( '[Objects] is not a valid array definition, please conform to the styleguide' ) ,
184
+ throw new Error (
185
+ '[Objects] is not a valid array definition, please conform to the styleguide' ,
180
186
) ;
181
- return 'any[]' ;
182
187
case 'object' :
183
- debug ( chalk . yellow ( 'Unstructured "Object" type specified' ) ) ;
184
- return 'any' ;
188
+ throw new Error (
189
+ 'Unstructured "Object" type specified, you must specify either the type of the object or provide the key structure inline in the documentation' ,
190
+ ) ;
185
191
case 'any' :
186
192
return 'any' ;
187
193
case 'string' :
@@ -201,14 +207,12 @@ export const typify = (
201
207
if ( innerTypes ) {
202
208
return `Promise<${ prefixTypeForSafety ( typify ( innerTypes [ 0 ] ) ) } >` ;
203
209
}
204
- debug ( chalk . red ( 'Promise with missing inner type, defaulting to any' ) ) ;
205
- return 'Promise<any>' ;
210
+ throw new Error ( 'Promise with missing inner type' ) ;
206
211
case 'record' :
207
212
if ( innerTypes && innerTypes . length === 2 ) {
208
213
return `Record<${ typify ( innerTypes [ 0 ] ) } , ${ typify ( innerTypes [ 1 ] ) } >` ;
209
214
}
210
- debug ( chalk . red ( 'Record with missing inner types, default to any' ) ) ;
211
- return 'Record<any, any>' ;
215
+ throw new Error ( 'Record with missing inner types' ) ;
212
216
case 'partial' :
213
217
if ( ! innerTypes || innerTypes . length !== 1 ) {
214
218
throw new Error ( 'Partial generic type must have exactly one inner type. i.e. Partial<T>' ) ;
0 commit comments