@@ -269,7 +269,10 @@ export class XtTypeHierarchyResolver implements XtUpdatableTypeResolver {
269269 if ( ! this . isPrimitiveType ( typeHierarchy ) ) {
270270 // Find the reference to an non primitive type
271271 ret = this . types . get ( typeHierarchy ) as XtBaseTypeHierarchy ?? null ;
272- if ( ret == null ) throw new Error ( 'Type ' + typeHierarchy + ' not found in the type hierarchy.' ) ;
272+ if ( ret == null ) {
273+ // Either it's an unknown type, or the type is defined at a later stage. Let's keep a placeholder
274+ ret = new UNRESOLVED_TYPE ( typeHierarchy ) ;
275+ }
273276 } else {
274277 // Just create the hierarchy to the primitive type
275278 ret = new XtBaseTypeHierarchy ( typeHierarchy , handler ) ;
@@ -325,14 +328,25 @@ export class XtTypeHierarchyResolver implements XtUpdatableTypeResolver {
325328
326329 resolveAllTypeReferences ( ) :void {
327330 for ( const type of this . types . values ( ) ) {
328- const refs = type . listReferences ( ) ;
329- for ( const ref of Object . keys ( refs ) ) {
330- if ( refs [ ref ] . type == XtBaseTypeReference . UNRESOLVED_TYPE ) {
331- const refType = this . findType ( refs [ ref ] . toType , refs [ ref ] . field ) ;
332- if ( refType != null ) {
333- refs [ ref ] . type = refType . type ;
334- } else {
335- throw new Error ( 'Unable to resolve reference ' + ref + ' of type ' + type . type ) ;
331+ if ( type . children != null ) {
332+ for ( const ref of Object . keys ( type . children ) ) {
333+ const subType = type . children [ ref ] ;
334+ if ( isTypeReference ( subType ) ) {
335+ if ( subType . type == XtBaseTypeReference . UNRESOLVED_TYPE ) {
336+ const refType = this . findType ( subType . toType , subType . field ) ;
337+ if ( refType != null ) {
338+ subType . type = refType . type ;
339+ } else {
340+ throw new Error ( 'Unable to resolve reference ' + ref + ' of type ' + type . type ) ;
341+ }
342+ }
343+ } else if ( isUnresolvedType ( subType ) ) {
344+ const realType = this . findType ( subType . unknownType ) ;
345+ if ( realType != null ) {
346+ type . children [ ref ] = realType ;
347+ } else {
348+ throw new Error ( 'Unable to resolve type ' + ref + ' of type ' + type . type + '. ' + subType . unknownType + ' is not defined.' ) ;
349+ }
336350 }
337351 }
338352 }
@@ -367,6 +381,7 @@ export class XtBaseTypeHierarchy implements XtTypeHierarchy {
367381 displayTemplate ?:string ;
368382 numericField ?:string ;
369383
384+
370385 constructor ( type :string , handler ?:XtTypeHandler < any > ) {
371386 this . type = type ;
372387 this . handler = handler ;
@@ -412,6 +427,22 @@ export class XtBaseTypeHierarchy implements XtTypeHierarchy {
412427 }
413428}
414429
430+ export class UNRESOLVED_TYPE extends XtBaseTypeHierarchy {
431+ unknownType :string | null = null ;
432+
433+ constructor ( unknownType :string ) {
434+ super ( unknownType ) ;
435+ this . unknownType = unknownType ;
436+ }
437+ }
438+
439+ export function isUnresolvedType ( type : XtTypeHierarchy ) : type is UNRESOLVED_TYPE {
440+ if ( ( type as any ) . unknownType !== undefined ) return true ;
441+ else
442+ return false ;
443+ }
444+
445+
415446/**
416447 * Internally manages a link between two types
417448 */
0 commit comments