private static TsType extractOriginalTsType ( TsType type ) { if ( type instanceof TsType . OptionalType ) { return extractOriginalTsType ( ( ( TsType . OptionalType ) type ) . type ) ; } if ( type instanceof TsType . UnionType ) { TsType . UnionType union = ( TsType . UnionType ) type ; List < TsType > originalTypes = new ArrayList <> ( ) ; for ( TsType curType : union . types ) { if ( isOriginalTsType ( curType ) ) { originalTypes . add ( curType ) ; } } return originalTypes . size ( ) == 1 ? extractOriginalTsType ( originalTypes . get ( 0 ) ) : type ; } if ( type instanceof TsType . BasicArrayType ) { return extractOriginalTsType ( ( ( TsType . BasicArrayType ) type ) . elementType ) ; } return type ; }
If the type is optional of number|null|undefined or list of of integer we want to be able to recognize it as number to link the member to another class . = > extract the original type while ignoring the |null|undefined and optional informations .