@@ -9,24 +9,66 @@ Test('Should Ref 1', () => {
99 const T : Type . TString = Type . Instantiate ( { A } , R )
1010 Assert . IsTrue ( Type . IsString ( T ) )
1111} )
12- Test ( 'Should Ref 1 ' , ( ) => {
12+ Test ( 'Should Ref 2 ' , ( ) => {
1313 const A = Type . String ( )
1414 const R = Type . Ref ( 'B' )
1515 const T : Type . TRef < 'B' > = Type . Instantiate ( { A } , R )
1616 Assert . IsTrue ( Type . IsRef ( T ) )
1717 Assert . IsEqual ( T . $ref , 'B' )
1818} )
19- Test ( 'Should Ref 1 ' , ( ) => {
19+ Test ( 'Should Ref 3 ' , ( ) => {
2020 const A = Type . Ref ( 'B' )
2121 const B = Type . Ref ( 'A' )
2222 const T : Type . TRef < 'A' > = Type . Instantiate ( { A, B } , B )
2323 Assert . IsTrue ( Type . IsRef ( T ) )
2424 Assert . IsEqual ( T . $ref , 'A' )
2525} )
26- Test ( 'Should Ref 1 ' , ( ) => {
26+ Test ( 'Should Ref 4 ' , ( ) => {
2727 const A = Type . Ref ( 'B' )
2828 const B = Type . Ref ( 'A' )
2929 const T : Type . TRef < 'A' > = Type . Instantiate ( { A, B } , B )
3030 Assert . IsTrue ( Type . IsRef ( T ) )
3131 Assert . IsEqual ( T . $ref , 'A' )
3232} )
33+ // ------------------------------------------------------------------
34+ // https://github.com/sinclairzx81/typebox/issues/1522
35+ //
36+ // Non-Instantiated Ref Must Retain Options
37+ // ------------------------------------------------------------------
38+ Test ( 'Should Ref 5' , ( ) => {
39+ const T : Type . TRef < 'A' > = Type . Ref ( 'A' , { foo : 'bar' } )
40+ const S = Type . Instantiate ( { } , T ) // no-target
41+
42+ Assert . IsTrue ( Type . IsRef ( S ) )
43+ Assert . IsEqual ( S . $ref , 'A' )
44+ Assert . HasPropertyKey ( S , 'foo' )
45+ Assert . IsEqual ( S . foo , 'bar' )
46+ } )
47+ Test ( 'Should Ref 6' , ( ) => {
48+ const T : Type . TRef < 'A' > = Type . Ref ( 'A' , { foo : 'bar' } )
49+ const S : Type . TString = Type . Instantiate ( { A : Type . String ( { foo : 'baz' } ) } , T )
50+
51+ Assert . IsTrue ( Type . IsString ( S ) )
52+ Assert . HasPropertyKey ( S , 'foo' )
53+ Assert . IsEqual ( S . foo , 'baz' )
54+ } )
55+ Test ( 'Should Ref 7' , ( ) => {
56+ const R : Type . TRecord < '^.*$' , Type . TRef < 'A' > > = Type . Record ( Type . String ( ) , Type . Ref ( 'A' , { foo : 'bar' } ) )
57+ const S : Type . TRecord < '^.*$' , Type . TRef < 'A' > > = Type . Instantiate ( { } , R ) // no-target
58+ const V : Type . TRef < 'A' > = Type . RecordValue ( S )
59+
60+ Assert . IsTrue ( Type . IsRecord ( S ) )
61+ Assert . IsEqual ( V . $ref , 'A' )
62+ Assert . HasPropertyKey ( V , 'foo' )
63+ Assert . IsEqual ( V . foo , 'bar' )
64+ } )
65+ Test ( 'Should Ref 8' , ( ) => {
66+ const R : Type . TRecord < '^.*$' , Type . TRef < 'A' > > = Type . Record ( Type . String ( ) , Type . Ref ( 'A' , { foo : 'bar' } ) )
67+ const S : Type . TRecord < '^.*$' , Type . TString > = Type . Instantiate ( { A : Type . String ( { foo : 'baz' } ) } , R )
68+ const V : Type . TString = Type . RecordValue ( S )
69+
70+ Assert . IsTrue ( Type . IsRecord ( S ) )
71+ Assert . IsTrue ( Type . IsString ( V ) )
72+ Assert . HasPropertyKey ( V , 'foo' )
73+ Assert . IsEqual ( V . foo , 'baz' )
74+ } )
0 commit comments