@@ -14,7 +14,7 @@ export type ScalarSchema = {
1414export type NormalizedScalarSchema = {
1515 name ?: never ;
1616 type ?: 'string' | 'boolean' | 'number' | 'integer' | 'object' | 'array' ;
17- items ?: ScalarSchema ;
17+ items ?: NormalizedScalarSchema ;
1818 enum ?: string [ ] ;
1919 directResolveAs ?: NormalizedNodeType ;
2020 resolvable : boolean ;
@@ -46,7 +46,7 @@ export type NormalizedNodeType = {
4646 requiredOneOf ?: string [ ] ;
4747 allowed ?: ( value : any ) => string [ ] | undefined ;
4848 extensionsPrefix ?: string ;
49- directResolveAs ?: NormalizedPropType ;
49+ directResolveAs ?: NormalizedNodeType ;
5050 description ?: string ;
5151 documentationLink ?: string ;
5252} ;
@@ -122,7 +122,7 @@ export function normalizeTypes(
122122
123123 if ( options . doNotResolveExamples && prop && ( prop as ScalarSchema ) . isExample ) {
124124 mappedProps [ propName ] = {
125- ...( prop as object ) ,
125+ ...prop ,
126126 resolvable : false ,
127127 } ;
128128 }
@@ -132,24 +132,25 @@ export function normalizeTypes(
132132 }
133133
134134 // typings are painful here...
135- function resolveType ( type ?: any ) : any {
135+ function resolveType (
136+ type : NormalizedPropType | NormalizedResolveTypeFn | string
137+ ) : NormalizedPropType | NormalizedResolveTypeFn {
136138 if ( typeof type === 'string' ) {
137139 if ( ! normalizedTypes [ type ] ) {
138140 throw new Error ( `Unknown type name found: ${ type } ` ) ;
139141 }
140142 return normalizedTypes [ type ] ;
141143 } else if ( typeof type === 'function' ) {
142- return ( value : any , key : string ) => {
143- return resolveType ( type ( value , key ) ) ;
144- } ;
145- } else if ( type && type . name ) {
144+ return ( value : unknown , key : string ) =>
145+ resolveType ( ( type as NormalizedResolveTypeFn ) ( value , key ) ) as NormalizedPropType ;
146+ } else if ( isNamedType ( type ) ) {
146147 type = { ...type } ;
147148 normalizeType ( type ) ;
148149 return type ;
149- } else if ( type && type . directResolveAs ) {
150+ } else if ( type ? .directResolveAs !== undefined ) {
150151 return {
151152 ...type ,
152- directResolveAs : resolveType ( type . directResolveAs ) ,
153+ directResolveAs : ( resolveType ( type . directResolveAs ) ?? undefined ) as NormalizedNodeType ,
153154 } ;
154155 } else {
155156 return type ;
0 commit comments