File tree Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Expand file tree Collapse file tree 1 file changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -341,22 +341,37 @@ export const getHookOptions = ({
341341 return value ;
342342} ;
343343
344+ // Helper to deduplicate union type string: "A | B | B" -> "A | B"
345+ const dedupeUnionTypes = ( types : string ) : string => {
346+ if ( ! types ) return types ;
347+ // Split by '|', trim spaces, filter out empty, and dedupe using a Set
348+ const unique = [
349+ ...new Set (
350+ types
351+ . split ( '|' )
352+ . map ( ( t ) => t . trim ( ) )
353+ . filter ( Boolean ) ,
354+ ) ,
355+ ] ;
356+ return unique . join ( ' | ' ) ;
357+ } ;
358+
344359export const getQueryErrorType = (
345360 operationName : string ,
346361 response : GetterResponse ,
347362 httpClient : OutputHttpClient ,
348363 mutator ?: GeneratorMutator ,
349364) => {
365+ const errorsType = dedupeUnionTypes ( response . definition . errors || 'unknown' ) ;
366+
350367 if ( mutator ) {
351368 return mutator . hasErrorType
352- ? `${ mutator . default ? pascal ( operationName ) : '' } ErrorType<${
353- response . definition . errors || 'unknown'
354- } >`
355- : response . definition . errors || 'unknown' ;
369+ ? `${ mutator . default ? pascal ( operationName ) : '' } ErrorType<${ errorsType } >`
370+ : errorsType ;
356371 } else {
357372 return httpClient === OutputHttpClient . AXIOS
358- ? `AxiosError<${ response . definition . errors || 'unknown' } >`
359- : response . definition . errors || 'unknown' ;
373+ ? `AxiosError<${ errorsType } >`
374+ : errorsType ;
360375 }
361376} ;
362377
You can’t perform that action at this time.
0 commit comments