@@ -11,11 +11,7 @@ import {
1111} from "collection-utils" ;
1212
1313import { StringTypes , stringTypesTypeAttributeKind } from "../attributes/StringTypes" ;
14- import {
15- type TypeAttributes ,
16- combineTypeAttributes ,
17- emptyTypeAttributes
18- } from "../attributes/TypeAttributes" ;
14+ import { type TypeAttributes , combineTypeAttributes , emptyTypeAttributes } from "../attributes/TypeAttributes" ;
1915import { assert , defined , panic } from "../support/Support" ;
2016
2117import { provenanceTypeAttributeKind } from "./ProvenanceTypeAttributeKind" ;
@@ -42,11 +38,12 @@ import {
4238 unionTypeIdentity
4339} from "./Type" ;
4440import { type StringTypeMapping , stringTypeMappingGet } from "./TypeBuilderUtils" ;
45- import { TypeGraph } from "./TypeGraph" ;
41+ import { type TypeGraph } from "./TypeGraph" ;
4642import { type TypeRef , assertTypeRefGraph , derefTypeRef , makeTypeRef , typeRefIndex } from "./TypeRef" ;
4743
4844export class TypeBuilder {
49- public readonly typeGraph : TypeGraph ;
45+ // @ts -expect-error must manually set TypeGraph
46+ private _typeGraph : TypeGraph ;
5047
5148 protected readonly topLevels : Map < string , TypeRef > = new Map ( ) ;
5249
@@ -57,7 +54,6 @@ export class TypeBuilder {
5754 private _addedForwardingIntersection = false ;
5855
5956 public constructor (
60- typeGraphSerial : number ,
6157 private readonly _stringTypeMapping : StringTypeMapping ,
6258 public readonly canonicalOrder : boolean ,
6359 private readonly _allPropertiesOptional : boolean ,
@@ -68,7 +64,16 @@ export class TypeBuilder {
6864 ! _addProvenanceAttributes || ! inheritsProvenanceAttributes ,
6965 "We can't both inherit as well as add provenance"
7066 ) ;
71- this . typeGraph = new TypeGraph ( this , typeGraphSerial , _addProvenanceAttributes || inheritsProvenanceAttributes ) ;
67+ }
68+
69+ public get typeGraph ( ) : TypeGraph {
70+ assert ( ! ! this . _typeGraph , "TypeBuilder must have a TypeGraph" ) ;
71+ return this . _typeGraph ;
72+ }
73+
74+ /** typeGraph must be set externally to prevent import cycle of TypeGraph constructor */
75+ public set typeGraph ( typeGraph : TypeGraph ) {
76+ this . _typeGraph = typeGraph ;
7277 }
7378
7479 public addTopLevel ( name : string , tref : TypeRef ) : void {
0 commit comments